Sfoglia il codice sorgente

displaylib: add D_get_file (https://trac.osgeo.org/grass/ticket/2509)
d.mon: use always full path for output files (even if using default file name) - https://trac.osgeo.org/grass/ticket/2509
d.mon: fix https://trac.osgeo.org/grass/ticket/2509 (d.mon output overwrite)
d.mon: stop monitor on failure (https://trac.osgeo.org/grass/ticket/2509)
displaylib: display driver lower case by default (cosmetics)
d.mon: print warning when overwritting the output file
(merge r63464-r63470 from trunk)


git-svn-id: https://svn.osgeo.org/grass/grass/branches/releasebranch_7_0@63533 15284696-431f-4ddb-bdfa-cd5b030d7da7

Martin Landa 10 anni fa
parent
commit
f5bd85bc82

+ 40 - 6
display/d.mon/start.c

@@ -2,6 +2,7 @@
 #include <string.h>
 #include <grass/gis.h>
 #include <grass/spawn.h>
+#include <grass/display.h>
 #include <grass/glocale.h>
 
 #include "proto.h"
@@ -9,16 +10,43 @@
 static void start(const char *, const char *);
 static void start_wx(const char *, const char *, const char *,
 		     const char *, int, int);
+static void error_handler(void *);
 
 /* start file-based monitor */
 void start(const char *name, const char *output)
 {
     char *env_name, output_path[GPATH_MAX];
+    const char *output_name;
     
-    if (!output)
-	return;
+    /* stop monitor on failure */
+    G_add_error_handler(error_handler, (char *)name);
+    
+    if (!output) {
+        if (D_open_driver() != 0)
+            G_fatal_error(_("No graphics device selected. "
+                            "Use d.mon to select graphics device."));
+        output_name = D_get_file();
+        if (!output_name) 
+            return;
+        if (access(output_name, F_OK) == 0) {
+            if (G_get_overwrite()) {
+                G_warning(_("File '%s' already exists and will be overwritten"), output_name);
+            }
+            else {
+                D_close_driver();
+                G_fatal_error(_("option <%s>: <%s> exists."),
+                              "output", output_name);
+            }
+        }
+        D_close_driver(); /* must be called after check because this
+                           * function produces default map file */
+    }
+    else {
+        output_name = output;
+    }
 
-    if (!strchr(output, HOST_DIRSEP)) { /* relative path */
+        
+    if (!strchr(output_name, HOST_DIRSEP)) { /* relative path */
         char *ptr;
         
         if (!getcwd(output_path, GPATH_MAX))
@@ -28,13 +56,13 @@ void start(const char *name, const char *output)
             *(ptr++) = HOST_DIRSEP;
             *(ptr) = '\0';
         }
-        strcat(output_path, output);
+        strcat(output_path, output_name);
         G_message(_("Output file: %s"), output_path);
     }
     else {
-        strcpy(output_path, output); /* already full path */
+        strcpy(output_path, output_name); /* already full path */
     }
-    
+
     env_name = NULL;
     G_asprintf(&env_name, "MONITOR_%s_MAPFILE", G_store_upper(name));
     G_setenv(env_name, output_path);
@@ -157,3 +185,9 @@ int start_mon(const char *name, const char *output, int select,
     
     return 0;
 }
+
+void error_handler(void *p)
+{
+    const char *name = (const char *) p;
+    stop_mon(name);
+}

+ 2 - 0
include/defs/display.h

@@ -162,4 +162,6 @@ void D_encoding(const char *);
 void D_font_list(char ***, int *);
 void D_font_info(char ***, int *);
 
+const char *D_get_file(void);
+
 #endif /* GRASS_DISPLAYDEFS_H */

+ 1 - 0
lib/cairodriver/cairodriver.h

@@ -84,6 +84,7 @@ extern const struct driver *Cairo_Driver(void);
 
 extern void Cairo_Client_Close(void);
 extern int Cairo_Graph_set(void);
+extern const char *Cairo_Graph_get_file(void);
 extern void Cairo_Graph_close(void);
 extern void Cairo_Box(double, double, double, double);
 extern void Cairo_Set_window(double, double, double, double);

+ 3 - 2
lib/cairodriver/driver.c

@@ -3,7 +3,7 @@
 
   \brief GRASS cairo display driver - driver initialization
 
-  (C) 2007-2008, 2011 by Lars Ahlzen and the GRASS Development Team
+  (C) 2007-2014 by Lars Ahlzen and the GRASS Development Team
   
   This program is free software under the GNU General Public License
   (>=v2). Read the file COPYING that comes with GRASS for details.
@@ -31,6 +31,7 @@ const struct driver *Cairo_Driver(void)
     drv.Box = Cairo_Box;
     drv.Erase = Cairo_Erase;
     drv.Graph_set = Cairo_Graph_set;
+    drv.Graph_get_file = Cairo_Graph_get_file;
     drv.Graph_close = Cairo_Graph_close;
     drv.Line_width = Cairo_Line_width;
     drv.Set_window = Cairo_Set_window;
@@ -51,7 +52,7 @@ const struct driver *Cairo_Driver(void)
     drv.Set_font = Cairo_set_font;
     drv.Font_list = Cairo_font_list;
     drv.Font_info = Cairo_font_info;
-
+      
     initialized = 1;
 
     return &drv;

+ 10 - 0
lib/cairodriver/graph.c

@@ -286,6 +286,16 @@ int Cairo_Graph_set(void)
 }
 
 /*!
+  \brief Get render file
+
+  \return file name
+*/
+const char *Cairo_Graph_get_file(void)
+{
+    return ca.file_name;
+}
+ 
+/*!
   \brief Close driver
 */
 void Cairo_Graph_close(void)

+ 3 - 3
lib/display/r_raster.c

@@ -135,9 +135,9 @@ int D_open_driver(void)
     }
     
     const struct driver *drv =
-	(p && G_strcasecmp(p, "PNG")   == 0) ? PNG_Driver() :
-	(p && G_strcasecmp(p, "PS")    == 0) ? PS_Driver() :
-	(p && G_strcasecmp(p, "HTML")  == 0) ? HTML_Driver() :
+	(p && G_strcasecmp(p, "png")   == 0) ? PNG_Driver() :
+	(p && G_strcasecmp(p, "ps")    == 0) ? PS_Driver() :
+	(p && G_strcasecmp(p, "html")  == 0) ? HTML_Driver() :
 #ifdef USE_CAIRO
 	(p && G_strcasecmp(p, "cairo") == 0) ? Cairo_Driver() :
 	Cairo_Driver();

+ 12 - 0
lib/display/setup.c

@@ -17,6 +17,8 @@
 #include <grass/raster.h>
 #include <grass/display.h>
 
+#include "driver.h"
+
 /*!
   \brief Graphics frame setup
 
@@ -118,3 +120,13 @@ void D_setup2(int clear, int fit, double st, double sb, double sl, double sr)
     if (clear)
 	D_erase(DEFAULT_BG_COLOR);
 }
+
+/*!
+  \brief Get driver output file
+
+  \return file name or NULL if not defined
+*/
+const char *D_get_file(void)
+{
+    return COM_Graph_get_file();
+}

+ 3 - 1
lib/driver/driver.h

@@ -22,11 +22,12 @@ extern struct GFONT_CAP *ftcap;
 struct driver
 {
     char *name;
-    
+
     void (*Box)(double, double, double, double);
     void (*Erase)(void);
     int (*Graph_set)(void);
     void (*Graph_close)(void);
+    const char * (*Graph_get_file)(void);
     void (*Line_width)(double);
     void (*Set_window)(double, double, double, double);
     void (*Begin_raster)(int, int[2][2], double[2][2]);
@@ -82,6 +83,7 @@ extern void COM_Get_text_box(const char *, double *, double *, double *, double
 /* graph.c */
 extern int COM_Graph_set(void);
 extern void COM_Graph_close(void);
+extern const char *COM_Graph_get_file(void);
 
 /* line_width.c */
 extern void COM_Line_width(double);

+ 9 - 0
lib/driver/graph.c

@@ -1,3 +1,4 @@
+#include <stdlib.h>
 #include "driver.h"
 #include "driverlib.h"
 
@@ -13,3 +14,11 @@ void COM_Graph_close(void)
     if (driver->Graph_close)
 	(*driver->Graph_close) ();
 }
+
+const char *COM_Graph_get_file(void)
+{
+    if (driver->Graph_get_file)
+        return (*driver->Graph_get_file) ();
+
+    return NULL;
+}

+ 1 - 0
lib/htmldriver/driver.c

@@ -30,6 +30,7 @@ const struct driver *HTML_Driver(void)
     drv.Erase = NULL;
     drv.Graph_set = HTML_Graph_set;
     drv.Graph_close = HTML_Graph_close;
+    drv.Graph_get_file = NULL;
     drv.Line_width = NULL;
     drv.Set_window = NULL;
     drv.Begin_raster = NULL;

+ 2 - 1
lib/pngdriver/driver.c

@@ -3,7 +3,7 @@
 
   \brief GRASS png display driver - driver initialization
 
-  (C) 2007 by Glynn Clements and the GRASS Development Team
+  (C) 2007-2014 by Glynn Clements and the GRASS Development Team
   
   This program is free software under the GNU General Public License
   (>=v2). Read the file COPYING that comes with GRASS for details.
@@ -31,6 +31,7 @@ const struct driver *PNG_Driver(void)
     drv.Erase = PNG_Erase;
     drv.Graph_set = PNG_Graph_set;
     drv.Graph_close = PNG_Graph_close;
+    drv.Graph_get_file = PNG_Graph_get_file;
     drv.Line_width = PNG_Line_width;
     drv.Set_window = PNG_Set_window;
     drv.Begin_raster = PNG_begin_raster;

+ 10 - 0
lib/pngdriver/graph_set.c

@@ -171,3 +171,13 @@ int PNG_Graph_set(void)
 
     return 0;
 }
+
+/*!
+  \brief Get render file
+
+  \return file name
+*/
+const char *PNG_Graph_get_file(void)
+{
+    return png.file_name;
+}

+ 1 - 0
lib/pngdriver/pngdriver.h

@@ -76,6 +76,7 @@ extern void PNG_Client_Close(void);
 extern void PNG_Erase(void);
 extern void PNG_Graph_close(void);
 extern int PNG_Graph_set(void);
+extern const char *PNG_Graph_get_file(void);
 extern void PNG_Line_width(double);
 extern void PNG_begin_raster(int, int[2][2], double[2][2]);
 extern int PNG_raster(int, int, const unsigned char *,

+ 1 - 0
lib/psdriver/driver.c

@@ -32,6 +32,7 @@ const struct driver *PS_Driver(void)
     drv.Erase = PS_Erase;
     drv.Graph_set = PS_Graph_set;
     drv.Graph_close = PS_Graph_close;
+    drv.Graph_get_file = PS_Graph_get_file;
     drv.Line_width = PS_Line_width;
     drv.Set_window = PS_Set_window;
     drv.Begin_raster = PS_begin_raster;

+ 10 - 0
lib/psdriver/graph_set.c

@@ -220,6 +220,16 @@ int PS_Graph_set(void)
     return 0;
 }
 
+/*!
+  \brief Get render file
+
+  \return file name
+*/
+const char *PS_Graph_get_file(void)
+{
+    return file_name;
+}
+
 void output(const char *fmt, ...)
 {
     va_list va;

+ 1 - 0
lib/psdriver/psdriver.h

@@ -31,6 +31,7 @@ extern void PS_Client_Close(void);
 extern void PS_Erase(void);
 extern void PS_Graph_close(void);
 extern int PS_Graph_set(void);
+extern const char *PS_Graph_get_file(void);
 extern void PS_Line_width(double);
 extern void PS_Set_window(double, double, double, double);
 extern void PS_Color(int, int, int);