Skip to content

Commit 777467e

Browse files
author
jef
committed
GRASS raster support works with MSVC
- let user know when a grass raster layer could not be inserted - some fixes for the GRASS DLL build - add grass_I (needed by GDAL's GRASS driver) builds with current GDAL + http://trac.osgeo.org/gdal/ticket/1983 and current GRASS CVS (one bug fix should be applied soon). git-svn-id: http://svn.osgeo.org/qgis/trunk@7377 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent b336c7b commit 777467e

File tree

7 files changed

+94
-17
lines changed

7 files changed

+94
-17
lines changed

src/plugins/grass/qgsgrassplugin.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,10 @@ void QgsGrassPlugin::addRaster()
414414

415415
//qGisInterface->addRasterLayer( uri );
416416
QgsRasterLayer *layer = new QgsRasterLayer( uri, sel->map );
417+
if( !layer->isValid() ) {
418+
// let the user know something went wrong - addRasterLayer cleans up
419+
QMessageBox::warning( 0, tr("Warning"), tr("Could not add raster layer: " ) + uri);
420+
}
417421
qGisInterface->addRasterLayer(layer);
418422

419423
mCanvas->refresh();

src/providers/grass/provider.cpp

-9
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,12 @@
2727
#include "qgsfield.h"
2828
#include "qgsrect.h"
2929

30-
#ifdef _MSC_VER
31-
// enables prototype in GRASS headers
32-
#define __STDC__ 1
33-
#endif
34-
3530
extern "C" {
3631
#include <grass/gis.h>
3732
#include <grass/dbmi.h>
3833
#include <grass/Vect.h>
3934
}
4035

41-
#ifdef _MSC_VER
42-
#undef __STDC__
43-
#endif
44-
4536
#include "qgsgrass.h"
4637
#include "qgsgrassprovider.h"
4738

src/providers/grass/vc/CMakeLists.txt

+46-3
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ ADD_DEFINITIONS(
66
-I${CMAKE_CURRENT_SOURCE_DIR}
77
-I${GRASS_PREFIX}/lib/db/dbmi_base
88
-I${ZLIB_INCLUDE_DIR}
9-
-D__MINGW32__)
10-
9+
-D__MINGW32__
10+
-Dpopen=G_popen
11+
-Dpclose=G_pclose)
1112

1213
ADD_LIBRARY (xdr STATIC
1314
xdr.c
@@ -396,6 +397,7 @@ ADD_LIBRARY (grass_dbmibase SHARED
396397
${GRASS_PREFIX}/lib/db/dbmi_base/xdrvalue.c
397398
${GRASS_PREFIX}/lib/db/dbmi_base/zero.c
398399
)
400+
SET_SOURCE_FILES_PROPERTIES(${GRASS_PREFIX}/lib/db/dbmi_base/xdr.c PROPERTIES COMPILE_FLAGS -U__MINGW32__)
399401
SET_TARGET_PROPERTIES(grass_dbmibase PROPERTIES LINK_FLAGS "/def:${CMAKE_CURRENT_SOURCE_DIR}/grass_dbmibase.def")
400402
TARGET_LINK_LIBRARIES(grass_dbmibase grass_gis)
401403

@@ -408,7 +410,7 @@ ADD_LIBRARY (grass_linkm SHARED
408410
${GRASS_PREFIX}/lib/linkm/oom.c
409411
)
410412
SET_TARGET_PROPERTIES(grass_linkm PROPERTIES LINK_FLAGS "/def:${CMAKE_CURRENT_SOURCE_DIR}/grass_linkm.def")
411-
413+
412414
ADD_LIBRARY (grass_dbmiclient SHARED
413415
${GRASS_PREFIX}/lib/db/dbmi_client/column.c
414416
${GRASS_PREFIX}/lib/db/dbmi_client/copy_tab.c
@@ -451,6 +453,46 @@ ADD_LIBRARY (grass_dbmiclient SHARED
451453
)
452454
SET_TARGET_PROPERTIES(grass_dbmiclient PROPERTIES LINK_FLAGS "/def:${CMAKE_CURRENT_SOURCE_DIR}/grass_dbmiclient.def")
453455
TARGET_LINK_LIBRARIES(grass_dbmiclient grass_dbmibase)
456+
457+
ADD_LIBRARY (grass_I SHARED
458+
${GRASS_PREFIX}/lib/imagery/alloc.c
459+
${GRASS_PREFIX}/lib/imagery/ask_group.c
460+
${GRASS_PREFIX}/lib/imagery/c_assign.c
461+
${GRASS_PREFIX}/lib/imagery/c_begin.c
462+
${GRASS_PREFIX}/lib/imagery/c_clear.c
463+
${GRASS_PREFIX}/lib/imagery/c_distinct.c
464+
${GRASS_PREFIX}/lib/imagery/c_exec.c
465+
${GRASS_PREFIX}/lib/imagery/c_execmem.c
466+
${GRASS_PREFIX}/lib/imagery/c_means.c
467+
${GRASS_PREFIX}/lib/imagery/c_merge.c
468+
${GRASS_PREFIX}/lib/imagery/c_nclasses.c
469+
${GRASS_PREFIX}/lib/imagery/c_point.c
470+
${GRASS_PREFIX}/lib/imagery/c_reassign.c
471+
${GRASS_PREFIX}/lib/imagery/c_reclass.c
472+
${GRASS_PREFIX}/lib/imagery/c_sep.c
473+
${GRASS_PREFIX}/lib/imagery/c_sig.c
474+
${GRASS_PREFIX}/lib/imagery/c_sum2.c
475+
${GRASS_PREFIX}/lib/imagery/eol.c
476+
${GRASS_PREFIX}/lib/imagery/find.c
477+
${GRASS_PREFIX}/lib/imagery/fopen.c
478+
${GRASS_PREFIX}/lib/imagery/georef.c
479+
${GRASS_PREFIX}/lib/imagery/group.c
480+
${GRASS_PREFIX}/lib/imagery/list_gp.c
481+
${GRASS_PREFIX}/lib/imagery/list_subgp.c
482+
${GRASS_PREFIX}/lib/imagery/loc_info.c
483+
${GRASS_PREFIX}/lib/imagery/ls_groups.c
484+
${GRASS_PREFIX}/lib/imagery/points.c
485+
${GRASS_PREFIX}/lib/imagery/ref.c
486+
${GRASS_PREFIX}/lib/imagery/sig.c
487+
${GRASS_PREFIX}/lib/imagery/sigfile.c
488+
${GRASS_PREFIX}/lib/imagery/sigset.c
489+
${GRASS_PREFIX}/lib/imagery/sigsetfile.c
490+
${GRASS_PREFIX}/lib/imagery/target.c
491+
${GRASS_PREFIX}/lib/imagery/title.c
492+
${GRASS_PREFIX}/lib/imagery/var.c
493+
)
494+
SET_TARGET_PROPERTIES(grass_I PROPERTIES LINK_FLAGS "/def:${CMAKE_CURRENT_SOURCE_DIR}/grass_I.def")
495+
TARGET_LINK_LIBRARIES(grass_I grass_gis)
454496

455497
INSTALL(TARGETS
456498
grass_gis
@@ -462,5 +504,6 @@ INSTALL(TARGETS
462504
grass_dbmibase
463505
grass_linkm
464506
grass_dbmiclient
507+
grass_I
465508
RUNTIME DESTINATION ${QGIS_BIN_DIR}
466509
ARCHIVE DESTINATION lib)

src/providers/grass/vc/dirent.h

+26
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ typedef struct DIR {
8383
static DIR *opendir (const char *dirname);
8484
static struct dirent *readdir (DIR *dirp);
8585
static int closedir (DIR *dirp);
86+
static void rewinddir (DIR *dirp);
8687

8788

8889
/* use the new safe string functions introduced in Visual Studio 2005 */
@@ -222,6 +223,31 @@ readdir(
222223
return &dirp->current;
223224
}
224225

226+
/*
227+
* Rewind the directory
228+
*
229+
*/
230+
static void
231+
rewinddir(
232+
DIR *dirp)
233+
{
234+
assert (dirp != NULL);
235+
236+
/* release search handle */
237+
if (dirp->search_handle != INVALID_HANDLE_VALUE) {
238+
FindClose (dirp->search_handle);
239+
dirp->search_handle = INVALID_HANDLE_VALUE;
240+
}
241+
242+
/* open stream and retrieve first file */
243+
dirp->search_handle = FindFirstFile (dirp->patt, &dirp->current.data);
244+
if (dirp->search_handle == INVALID_HANDLE_VALUE) {
245+
return;
246+
}
247+
248+
/* there is an un-processed directory entry in memory now */
249+
dirp->cached = 1;
250+
}
225251

226252
/*
227253
* Close directory stream opened by opendir() function. Close of the

src/providers/grass/vc/grass_gis.def

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
LIBRARY grass_gis.dll
22
EXPORTS
3-
; xdrmem_create @ 1
4-
; DllMainCRTStartup@12 @ 2
5-
; FindAtomA@4 @ 3 DATA
63
G_3dview_warning @ 4
74
G__ @ 5 DATA
85
G__allocate_null_bits @ 6
@@ -178,7 +175,7 @@ EXPORTS
178175
G_color_name @ 175
179176
G_color_values @ 176
180177
G_colors_count @ 177
181-
G_command_history @ 178
178+
; G_command_history @ 178
182179
G_compare_projections @ 179
183180
G_construct_default_range @ 180
184181
G_convert_dirseps_from_host @ 181

src/providers/grass/vc/rpc/types.h

+5
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,9 @@ typedef unsigned long u_long;
9696
typedef unsigned short u_short;
9797
#endif
9898

99+
#ifdef _MSC_VER
100+
#include <basetsd.h>
101+
typedef SSIZE_T ssize_t;
102+
#endif //_MSC_VER
103+
99104
#endif /* ndef __TYPES_RPC_HEADER__ */

src/providers/grass/vc/unistd.h

+12-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,12 @@
1-
#include <io.h>
1+
#include <io.h>
2+
#include <windows.h>
3+
#include <process.h>
4+
#include <direct.h>
5+
6+
#define getpid() GetCurrentProcessId()
7+
#define chmod(f,m)
8+
#define rmdir _rmdir
9+
10+
#ifndef S_ISDIR
11+
#define S_ISDIR(x) (((x) & S_IFMT) == S_IFDIR)
12+
#endif

0 commit comments

Comments
 (0)