Browse Source

wxGUI/vdigit: fill valid areas (closed boundary + centroid)

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@32132 15284696-431f-4ddb-bdfa-cd5b030d7da7
Martin Landa 17 years ago
parent
commit
0a89d7869d
3 changed files with 105 additions and 21 deletions
  1. 6 0
      gui/wxpython/gui_modules/vdigit.py
  2. 94 21
      gui/wxpython/vdigit/driver.cpp
  3. 5 0
      gui/wxpython/vdigit/driver.h

+ 6 - 0
gui/wxpython/gui_modules/vdigit.py

@@ -1563,6 +1563,11 @@ class CDisplayDriver(AbstractDisplayDriver):
                                                 UserSettings.Get(group='vdigit', key='symbolVertex', subkey='color')[1],
                                                 UserSettings.Get(group='vdigit', key='symbolVertex', subkey='color')[1],
                                                 UserSettings.Get(group='vdigit', key='symbolVertex', subkey='color')[2],
                                                 UserSettings.Get(group='vdigit', key='symbolVertex', subkey='color')[2],
                                                 255).GetRGB(),
                                                 255).GetRGB(),
+                                       UserSettings.Get(group='vdigit', key='symbolArea', subkey='enabled'),
+                                       wx.Color(UserSettings.Get(group='vdigit', key='symbolArea', subkey='color')[0],
+                                                UserSettings.Get(group='vdigit', key='symbolArea', subkey='color')[1],
+                                                UserSettings.Get(group='vdigit', key='symbolArea', subkey='color')[2],
+                                                255).GetRGB(),
                                        UserSettings.Get(group='vdigit', key='symbolDirection', subkey='enabled'),
                                        UserSettings.Get(group='vdigit', key='symbolDirection', subkey='enabled'),
                                        wx.Color(UserSettings.Get(group='vdigit', key='symbolDirection', subkey='color')[0],
                                        wx.Color(UserSettings.Get(group='vdigit', key='symbolDirection', subkey='color')[0],
                                                 UserSettings.Get(group='vdigit', key='symbolDirection', subkey='color')[1],
                                                 UserSettings.Get(group='vdigit', key='symbolDirection', subkey='color')[1],
@@ -1975,6 +1980,7 @@ class VDigitSettingsDialog(wx.Dialog):
             (_("Node (one line)"), "symbolNodeOne"),
             (_("Node (one line)"), "symbolNodeOne"),
             (_("Node (two lines)"), "symbolNodeTwo"),
             (_("Node (two lines)"), "symbolNodeTwo"),
             (_("Vertex"), "symbolVertex"),
             (_("Vertex"), "symbolVertex"),
+            (_("Area (closed boundary + centroid)"), "symbolArea"),
             (_("Direction"), "symbolDirection"),)
             (_("Direction"), "symbolDirection"),)
 
 
     def OnChangeCategoryMode(self, event):
     def OnChangeCategoryMode(self, event):

+ 94 - 21
gui/wxpython/vdigit/driver.cpp

@@ -119,6 +119,34 @@ int DisplayDriver::DrawMap(bool force)
 	    region.box.W, region.box.E, region.box.S, region.box.N);
 	    region.box.W, region.box.E, region.box.S, region.box.N);
 
 
     dc->BeginDrawing();
     dc->BeginDrawing();
+
+    if (settings.area.enabled) {
+	/* draw area fills first */
+	int area;
+	struct ilist *listAreas, *listCentroids;
+	BOUND_BOX areaBox;
+
+	listAreas = Vect_new_list();
+	listCentroids = Vect_new_list();
+
+	Vect_select_areas_by_box(mapInfo, &(region.box),
+				 listAreas);
+
+	for (int i = 0; i < listAreas->n_values; i++) {
+	    area = listAreas->value[i];
+	    /* 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);
+	    }
+	}
+
+	Vect_destroy_list(listAreas);
+	Vect_destroy_list(listCentroids);
+    }
+
     for (int i = 0; i < listLines->n_values; i++) {
     for (int i = 0; i < listLines->n_values; i++) {
 	DrawLine(listLines->value[i]);
 	DrawLine(listLines->value[i]);
     }
     }
@@ -132,27 +160,67 @@ int DisplayDriver::DrawMap(bool force)
 }	
 }	
 
 
 /**
 /**
+   \brief Draw area fill
+
+   \param area area id
+
+   \return 1 on success
+   \return -1 on failure (vector object is dead, etc.)
+*/
+int DisplayDriver::DrawArea(int area)
+{
+    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];
+
+    for (int i = 0; i < points->n_points; i++) {
+	Cell2Pixel(points->x[i], points->y[i], points->z[i],
+		   &x, &y, &z);
+	wxPoints[i] = wxPoint((int) x, (int) y);
+    }
+
+    // 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;
+}
+
+/**
    \brief Draw selected vector objects to the device
    \brief Draw selected vector objects to the device
  
  
    \param[in] line id
    \param[in] line id
+
    \return 1 on success
    \return 1 on success
    \return -1 on failure (vector object is dead, etc.)
    \return -1 on failure (vector object is dead, etc.)
 */
 */
 int DisplayDriver::DrawLine(int line)
 int DisplayDriver::DrawLine(int line)
 {
 {
-    if (!dc || !Vect_line_alive (mapInfo, line))
-	return -1;
-
-    int dcId;    // 0 | 1 | segment id
-    int type;    // line type
+    int dcId;       // 0 | 1 | segment id
+    int type;       // line type
     double x, y, z; // screen coordinates
     double x, y, z; // screen coordinates
-    bool draw;   // draw object ?
-
+    bool draw;      // draw object ?
     wxPen *pen;
     wxPen *pen;
-
+    
     pen = NULL;
     pen = NULL;
     draw = false;
     draw = false;
 
 
+    if (!dc || !Vect_line_alive (mapInfo, line))
+	return -1;
+
     // read line
     // read line
     type = Vect_read_line (mapInfo, points, cats, line);
     type = Vect_read_line (mapInfo, points, cats, line);
 
 
@@ -260,19 +328,19 @@ int DisplayDriver::DrawLine(int line)
 	    if (dcId > 0 && drawSegments) {
 	    if (dcId > 0 && drawSegments) {
 		dcId = 2; // first segment
 		dcId = 2; // first segment
 		for (size_t i = 0; i < pointsScreen->GetCount() - 1; dcId += 2) {
 		for (size_t i = 0; i < pointsScreen->GetCount() - 1; dcId += 2) {
-		wxPoint *point_beg = (wxPoint *) pointsScreen->Item(i)->GetData();
-		wxPoint *point_end = (wxPoint *) pointsScreen->Item(++i)->GetData();
-
-		// set bounds for line
-		// wxRect rect (*point_beg, *point_end);
-		// dc->SetIdBounds(startId, rect);
-		
-		dc->SetId(dcId); // set unique id & set bbox for each segment
-		dc->SetPen(*pen);
-		wxRect rect (*point_beg, *point_end);
-		dc->SetIdBounds(dcId, rect);
-		dc->DrawLine(point_beg->x, point_beg->y,
-			     point_end->x, point_end->y);
+		    wxPoint *point_beg = (wxPoint *) pointsScreen->Item(i)->GetData();
+		    wxPoint *point_end = (wxPoint *) pointsScreen->Item(++i)->GetData();
+		    
+		    // set bounds for line
+		    // wxRect rect (*point_beg, *point_end);
+		    // dc->SetIdBounds(startId, rect);
+		    
+		    dc->SetId(dcId); // set unique id & set bbox for each segment
+		    dc->SetPen(*pen);
+		    wxRect rect (*point_beg, *point_end);
+		    dc->SetIdBounds(dcId, rect);
+		    dc->DrawLine(point_beg->x, point_beg->y,
+				 point_end->x, point_end->y);
 		}
 		}
 	    }
 	    }
 	    else {
 	    else {
@@ -281,6 +349,7 @@ int DisplayDriver::DrawLine(int line)
 		    wxPoint *point_beg = (wxPoint *) pointsScreen->Item(i)->GetData();
 		    wxPoint *point_beg = (wxPoint *) pointsScreen->Item(i)->GetData();
 		    wxPoints[i] = *point_beg;
 		    wxPoints[i] = *point_beg;
 		}
 		}
+		
 		dc->DrawLines(pointsScreen->GetCount(), wxPoints);
 		dc->DrawLines(pointsScreen->GetCount(), wxPoints);
 
 
 		if (!IsSelected(line) && settings.direction.enabled) {
 		if (!IsSelected(line) && settings.direction.enabled) {
@@ -687,6 +756,7 @@ void DisplayDriver::UpdateSettings(unsigned long highlight,
 				   bool eNodeOne,     unsigned long cNodeOne,
 				   bool eNodeOne,     unsigned long cNodeOne,
 				   bool eNodeTwo,     unsigned long cNodeTwo,
 				   bool eNodeTwo,     unsigned long cNodeTwo,
 				   bool eVertex,      unsigned long cVertex,
 				   bool eVertex,      unsigned long cVertex,
+				   bool eArea,        unsigned long cArea,
 				   bool eDirection,   unsigned long cDirection,
 				   bool eDirection,   unsigned long cDirection,
 				   int lineWidth)
 				   int lineWidth)
 {
 {
@@ -724,6 +794,9 @@ void DisplayDriver::UpdateSettings(unsigned long highlight,
     settings.vertex.enabled = eVertex;
     settings.vertex.enabled = eVertex;
     settings.vertex.color.Set(cVertex);
     settings.vertex.color.Set(cVertex);
 
 
+    settings.area.enabled = eArea;
+    settings.area.color.Set(cArea);
+
     settings.direction.enabled = eDirection;
     settings.direction.enabled = eDirection;
     settings.direction.color.Set(cDirection);
     settings.direction.color.Set(cDirection);
 
 

+ 5 - 0
gui/wxpython/vdigit/driver.h

@@ -107,6 +107,8 @@ private:
 
 
 	symbol vertex;
 	symbol vertex;
 
 
+	symbol area;
+
 	symbol direction;
 	symbol direction;
 
 
 	int lineWidth;    // screen units 
 	int lineWidth;    // screen units 
@@ -145,6 +147,8 @@ private:
     int DrawLineNodes(int);
     int DrawLineNodes(int);
     int DrawDirectionArrow();
     int DrawDirectionArrow();
 
 
+    int DrawArea(int);
+
     /* debug */
     /* debug */
     void PrintIds();
     void PrintIds();
 
 
@@ -207,6 +211,7 @@ public:
 			bool, unsigned long,
 			bool, unsigned long,
 			bool, unsigned long,
 			bool, unsigned long,
 			bool, unsigned long,
 			bool, unsigned long,
+			bool, unsigned long,
 			int);
 			int);
 };
 };