[GRASS-SVN] r32160 - in grass/branches/develbranch_6/gui/wxpython: gui_modules vdigit

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Jul 18 10:21:24 EDT 2008


Author: martinl
Date: 2008-07-18 10:21:24 -0400 (Fri, 18 Jul 2008)
New Revision: 32160

Modified:
   grass/branches/develbranch_6/gui/wxpython/gui_modules/preferences.py
   grass/branches/develbranch_6/gui/wxpython/vdigit/driver.cpp
   grass/branches/develbranch_6/gui/wxpython/vdigit/driver.h
Log:
wxGUI/vdigit: isles filled in white
check for valid areas disabled by default
(merged from trunk, r32159)


Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/preferences.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/preferences.py	2008-07-18 14:16:39 UTC (rev 32159)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/preferences.py	2008-07-18 14:21:24 UTC (rev 32160)
@@ -207,7 +207,7 @@
                     'color' : (255, 20, 147, 255)
                     }, # deep pink
                 'symbolArea' : {
-                    'enabled' : True,
+                    'enabled' : False,
                     'color' : (217, 255, 217, 255)
                     }, # green
                 'symbolDirection' : {

Modified: grass/branches/develbranch_6/gui/wxpython/vdigit/driver.cpp
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/vdigit/driver.cpp	2008-07-18 14:16:39 UTC (rev 32159)
+++ grass/branches/develbranch_6/gui/wxpython/vdigit/driver.cpp	2008-07-18 14:21:24 UTC (rev 32160)
@@ -122,27 +122,113 @@
 
     if (settings.area.enabled) {
 	/* draw area fills first */
-	int area;
+	int area, centroid, isle;
+	int num_isles;
+	bool draw;
 	struct ilist *listAreas, *listCentroids;
+	struct line_pnts *points, *ipoints, **isles;
 	BOUND_BOX areaBox;
 
+	wxBrush *fillArea, *fillIsle;
+
+	fillArea = new wxBrush(settings.area.color);
+	fillIsle = new wxBrush(*wxWHITE_BRUSH);
+	
 	listAreas = Vect_new_list();
 	listCentroids = Vect_new_list();
+	
+	points = Vect_new_line_struct();
+	ipoints = NULL;
 
-	Vect_select_areas_by_box(mapInfo, &(region.box),
+	Vect_select_areas_by_box(mapInfo, &region.box,
 				 listAreas);
 
 	for (int i = 0; i < listAreas->n_values; i++) {
 	    area = listAreas->value[i];
+	    
+	    if (!Vect_area_alive (mapInfo, area))
+		return -1;
+
 	    /* check for other centroids -- only area with one centroid is valid */
-	    Vect_get_area_box(mapInfo, area, &areaBox);
-	    
-	    if(Vect_select_lines_by_box(mapInfo, &areaBox,
-					GV_CENTROID, listCentroids) == 1) {
-		DrawArea(area);
+	    centroid = Vect_get_area_centroid(mapInfo, area);
+
+	    if(centroid > 0) {
+		/* check for isles */
+		num_isles = Vect_get_area_num_isles(mapInfo, area); /* TODO */
+		if (num_isles < 1)
+		    isles = NULL;
+		else
+		    isles = (struct line_pnts **) G_malloc(num_isles * sizeof(struct line_pnts *));
+		for (int j = 0; j < num_isles; j++) {
+		    ipoints = Vect_new_line_struct();
+		    isle = Vect_get_area_isle(mapInfo, area, j);
+
+		    if (!Vect_isle_alive (mapInfo, isle))
+			return -1;
+
+		    Vect_get_isle_points(mapInfo, isle, ipoints);
+		    isles[j] = ipoints;
+		}
+
+		Vect_get_area_points(mapInfo, area, points);
+
+		/* avoid processing areas with large number of polygon points (ugly) */
+		if (points->n_points < 5000) {
+		    Vect_select_lines_by_polygon(mapInfo, points,
+						 num_isles, isles, GV_CENTROID, listCentroids);
+		}
+		else {
+		    Vect_reset_list(listCentroids);
+		}
+
+		Vect_get_area_box(mapInfo, area, &areaBox);
+		if (areaBox.E > region.box.E && areaBox.W < region.box.W &&
+		    areaBox.S < region.box.S && areaBox.N > region.box.N) {
+
+		    Vect_reset_line(points);
+		    Vect_append_point(points, region.box.W, region.box.N, 0.0);
+		    Vect_append_point(points, region.box.E, region.box.N, 0.0);
+		    Vect_append_point(points, region.box.E, region.box.S, 0.0);
+		    Vect_append_point(points, region.box.W, region.box.S, 0.0);
+		    Vect_append_point(points, region.box.W, region.box.N, 0.0);
+		}
+
+		draw = true;
+		for (int c = 0; c < listCentroids->n_values; c++) {
+		    if(Vect_get_centroid_area(mapInfo, listCentroids->value[c]) < 0) {
+			draw = false;
+			break;
+		    }
+		}
+		
+		if (draw) {
+		    dc->SetBrush(*fillArea);
+		    dc->SetPen(*wxTRANSPARENT_PEN);
+		    DrawArea(points);
+
+		    for (int j = 0; j < num_isles; j++) {
+			/* draw isles in white */
+			dc->SetBrush(*fillIsle);
+			dc->SetPen(*wxTRANSPARENT_PEN);
+			DrawArea(isles[j]);
+		    }
+		}
+
+		if(isles) {
+		    for (int j = 0; j < num_isles; j++) {
+			Vect_destroy_line_struct(isles[j]);
+			isles[j] = NULL;
+		    }
+		    G_free((void *) isles);
+		}
 	    }
 	}
 
+	delete fillArea;
+	delete fillIsle;
+
+	Vect_destroy_line_struct(points);
+
 	Vect_destroy_list(listAreas);
 	Vect_destroy_list(listCentroids);
     }
@@ -153,7 +239,7 @@
     dc->EndDrawing();
 
     // PrintIds();
-
+    
     Vect_destroy_list(listLines);
 
     return listLines->n_values;
@@ -162,24 +248,15 @@
 /**
    \brief Draw area fill
 
-   \param area area id
+   \param area boundary points
 
    \return 1 on success
    \return -1 on failure (vector object is dead, etc.)
 */
-int DisplayDriver::DrawArea(int area)
+int DisplayDriver::DrawArea(const line_pnts* points)
 {
     double x, y, z;
-    struct line_pnts *points;
 
-    if (!dc || !Vect_area_alive (mapInfo, area))
-	return -1;
-
-    points = Vect_new_line_struct();
-
-    // get boundary points
-    Vect_get_area_points(mapInfo, area, points);
-
     // convert EN -> xy
     wxPoint wxPoints[points->n_points];
 
@@ -190,12 +267,8 @@
     }
 
     // draw polygon
-    dc->SetBrush(wxBrush(settings.area.color));
-    dc->SetPen(wxPen(settings.area.color));
     dc->DrawPolygon(points->n_points, wxPoints);
 
-    Vect_destroy_line_struct(points);
-
     return 1;
 }
 
@@ -796,7 +869,11 @@
 
     settings.area.enabled = eArea;
     settings.area.color.Set(cArea);
-
+    settings.area.color.Set(settings.area.color.Red(),
+			    settings.area.color.Green(),
+			    settings.area.color.Blue(),
+			    100); /* transparency */
+    
     settings.direction.enabled = eDirection;
     settings.direction.color.Set(cDirection);
 

Modified: grass/branches/develbranch_6/gui/wxpython/vdigit/driver.h
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/vdigit/driver.h	2008-07-18 14:16:39 UTC (rev 32159)
+++ grass/branches/develbranch_6/gui/wxpython/vdigit/driver.h	2008-07-18 14:21:24 UTC (rev 32160)
@@ -147,7 +147,7 @@
     int DrawLineNodes(int);
     int DrawDirectionArrow();
 
-    int DrawArea(int);
+    int DrawArea(const line_pnts *);
 
     /* debug */
     void PrintIds();



More information about the grass-commit mailing list