소스 검색

libdisplay: implement GRASS_RENDER_COMMAND
prepare D_save_command() for removal
(work in progress)


git-svn-id: https://svn.osgeo.org/grass/grass/trunk@64401 15284696-431f-4ddb-bdfa-cd5b030d7da7

Martin Landa 10 년 전
부모
커밋
7dcea7511b
1개의 변경된 파일45개의 추가작업 그리고 110개의 파일을 삭제
  1. 45 110
      lib/display/r_raster.c

+ 45 - 110
lib/display/r_raster.c

@@ -3,7 +3,7 @@
 
 
   \brief Display Library - Raster graphics subroutines
   \brief Display Library - Raster graphics subroutines
 
 
-  (C) 2001-2014 by the GRASS Development Team
+  (C) 2001-2015 by the GRASS Development Team
 
 
   This program is free software under the GNU General Public License
   This program is free software under the GNU General Public License
   (>=v2). Read the file COPYING that comes with GRASS for details.
   (>=v2). Read the file COPYING that comes with GRASS for details.
@@ -24,6 +24,7 @@
 #include <grass/gis.h>
 #include <grass/gis.h>
 #include <grass/glocale.h>
 #include <grass/glocale.h>
 #include <grass/display.h>
 #include <grass/display.h>
+#include <grass/spawn.h>
 
 
 #include "driver.h"
 #include "driver.h"
 
 
@@ -34,8 +35,6 @@ extern const struct driver *HTML_Driver(void);
 extern const struct driver *Cairo_Driver(void);
 extern const struct driver *Cairo_Driver(void);
 #endif
 #endif
 
 
-static int read_env_file(const char *);
-
 static struct {
 static struct {
     double t, b, l, r;
     double t, b, l, r;
 } screen;
 } screen;
@@ -71,79 +70,64 @@ static void init(void)
 	COM_Get_window(&screen.t, &screen.b, &screen.l, &screen.r);
 	COM_Get_window(&screen.t, &screen.b, &screen.l, &screen.r);
 }
 }
 
 
-int read_env_file(const char *path)
-{
-    FILE *fd;
-    char buf[1024];
-    char **token;
-
-    G_debug(1, "read_env_file(): %s", path);
-    
-    fd = fopen(path, "r");
-    if (!fd)
-	return -1;
-
-    token = NULL;
-    while (G_getl2(buf, sizeof(buf) - 1, fd) != 0) {
-	token = G_tokenize(buf, "=");
-	if (G_number_of_tokens(token) != 2)
-	    continue;
-	G_debug(3, "\tread_env_file(): %s=%s", token[0], token[1]);
-	G_putenv(token[0], token[1]);
-	G_free_tokens(token);
-	token = NULL;
-    }
-
-    return 0;
-}
-
 /*!
 /*!
   \brief Open display driver
   \brief Open display driver
 
 
   Default display driver is Cairo, if not available PNG is used.
   Default display driver is Cairo, if not available PNG is used.
 
 
   \return 0 on success
   \return 0 on success
-  \return 1 no monitor defined
 */
 */
 int D_open_driver(void)
 int D_open_driver(void)
 {
 {
-    const char *p, *m;
+    const char *p, *c, *m;
     const struct driver *drv;
     const struct driver *drv;
     
     
     G_debug(1, "D_open_driver():");
     G_debug(1, "D_open_driver():");
     p = getenv("GRASS_RENDER_IMMEDIATE");
     p = getenv("GRASS_RENDER_IMMEDIATE");
+    c = getenv("GRASS_RENDER_COMMAND");
     m = G_getenv_nofatal("MONITOR");
     m = G_getenv_nofatal("MONITOR");
     
     
-    if (m && G_strncasecmp(m, "wx", 2) == 0) {
-	/* wx monitors always use GRASS_RENDER_IMMEDIATE. */
-	p = NULL; /* use default display driver */
-    }
-    else if (m) {
-	char *env;
-	const char *v;
-	char *u_m;
-	
-	if (p)
-	    G_warning(_("%s variable defined, %s ignored"),
-		      "MONITOR", "GRASS_RENDER_IMMEDIATE");
-	/* GRASS variable names should be upper case. */
-	u_m = G_store_upper(m);
+    if (!p && (m || c)) {
+        char *cmd;
+        char progname[GPATH_MAX];
 
 
-	env = NULL;
-	G_asprintf(&env, "MONITOR_%s_MAPFILE", u_m);
-	v = G_getenv_nofatal(env);
-	p = m;
-
-	if (v)
-            G_putenv("GRASS_RENDER_FILE", v);
+        cmd = G_recreate_command();
+        
+        if (c && m) {
+            G_warning(_("Both %s and %s are defined. "
+                        "%s will be ignored."),
+                      "GRASS_RENDER_COMMAND", "MONITOR",
+                      "MONITOR");
+            m = NULL;
+        }
         
         
-	G_asprintf(&env, "MONITOR_%s_ENVFILE", u_m);
-	v = G_getenv_nofatal(env);
-	if (v) 
-	    read_env_file(v);
+        if (c) 
+            sprintf(progname, "%s", c);
+        else { /* monitors managed by d.mon -> call default renderer */
+            char element[GPATH_MAX];
+            
+            G_temp_element(element);
+            strcat(element, "/");
+            strcat(element, "MONITORS");
+            strcat(element, "/");
+            strcat(element, m);
+            G_file_name(progname, element, "render.py", G_mapset());
+        }
+        
+        /* assuming Python script here (could be extended in the future) */
+        G_spawn_ex(getenv("GRASS_PYTHON"), getenv("GRASS_PYTHON"), progname,
+                   cmd, NULL);
+        
+        G_free(cmd);
+        
+        /* force exiting GRASS command, leave rendering on
+         * GRASS_RENDER_COMMAND program */
+        exit(0);
     }
     }
-    else if (!p)
-	G_fatal_error(_("Neither %s (managed by d.mon command) nor %s (used for direct rendering) defined"),
+
+    if (!p)
+	G_fatal_error(_("Neither %s (managed by d.mon command) nor %s "
+                        "(used for direct rendering) defined"),
 		      "MONITOR", "GRASS_RENDER_IMMEDIATE");
 		      "MONITOR", "GRASS_RENDER_IMMEDIATE");
 
 
     if (p && G_strcasecmp(p, "default") == 0)
     if (p && G_strcasecmp(p, "default") == 0)
@@ -186,62 +170,13 @@ void D_close_driver(void)
 }
 }
 
 
 /*!
 /*!
-  \brief Append command to the cmd file
+  \brief Append command to the cmd file (unused)
 
 
-  Cmd file is created by d.mon by defining GRASS variable
-  \c MONITOR_<name>_CMDFILE, where \c \<name\> is the upper case name of
-  the monitor.
-
-  Command string is usually generated by G_recreate_command(), NULL is
-  used to clean up list of commands (see d.erase command).
-
-  \param cmd string buffer with command or NULL
-
-  \return 0 no monitor selected
-  \return -1 on error
-  \return 1 on success
+  \todo To be removed
 */
 */
 int D_save_command(const char *cmd)
 int D_save_command(const char *cmd)
 {
 {
-    const char *mon_name, *mon_cmd;
-    char *env, *flag, *u_mon_name;
-    FILE *fd;
-
-    G_debug(1, "D_save_command(): %s", cmd);
-
-    mon_name = G_getenv_nofatal("MONITOR");
-    if (!mon_name || /* if no monitor selected */
-	/* or wx monitor selected and display commands called by the monitor */
-	(G_strncasecmp(mon_name, "wx", 2) == 0 &&
-	 getenv("GRASS_RENDER_IMMEDIATE")))
-	return 0;
-
-    /* GRASS variable names should be upper case. */
-    u_mon_name = G_store_upper(mon_name);
-
-    env = NULL;
-    G_asprintf(&env, "MONITOR_%s_CMDFILE", u_mon_name);
-    mon_cmd = G_getenv_nofatal(env);
-    if (!mon_cmd)
-	return 0;
-
-    if (cmd)
-	flag = "a";
-    else
-	flag = "w";
-
-    fd = fopen(mon_cmd, flag);
-    if (!fd) {
-	G_warning(_("Unable to open file '%s'"), mon_cmd);
-	return -1;
-    }
-
-    if (cmd)
-	fprintf(fd, "%s\n", cmd);
-    
-    fclose(fd);
-
-    return 1;
+    return 0;
 }
 }
 
 
 /*!
 /*!