[GRASS-SVN] r32133 - in grass/branches/develbranch_6/gui/wxpython:
gui_modules vdigit
svn_grass at osgeo.org
svn_grass at osgeo.org
Wed Jul 16 10:57:50 EDT 2008
Author: martinl
Date: 2008-07-16 10:57:50 -0400 (Wed, 16 Jul 2008)
New Revision: 32133
Modified:
grass/branches/develbranch_6/gui/wxpython/gui_modules/vdigit.py
grass/branches/develbranch_6/gui/wxpython/vdigit/driver.cpp
grass/branches/develbranch_6/gui/wxpython/vdigit/driver.h
Log:
wxGUI/vdigit: fill valid areas (closed boundary + centroid)
[merged from trunk, r32132]
Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/vdigit.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/vdigit.py 2008-07-16 14:50:30 UTC (rev 32132)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/vdigit.py 2008-07-16 14:57:50 UTC (rev 32133)
@@ -1563,6 +1563,11 @@
UserSettings.Get(group='vdigit', key='symbolVertex', subkey='color')[1],
UserSettings.Get(group='vdigit', key='symbolVertex', subkey='color')[2],
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'),
wx.Color(UserSettings.Get(group='vdigit', key='symbolDirection', subkey='color')[0],
UserSettings.Get(group='vdigit', key='symbolDirection', subkey='color')[1],
@@ -1975,6 +1980,7 @@
(_("Node (one line)"), "symbolNodeOne"),
(_("Node (two lines)"), "symbolNodeTwo"),
(_("Vertex"), "symbolVertex"),
+ (_("Area (closed boundary + centroid)"), "symbolArea"),
(_("Direction"), "symbolDirection"),)
def OnChangeCategoryMode(self, event):
Modified: grass/branches/develbranch_6/gui/wxpython/vdigit/driver.cpp
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/vdigit/driver.cpp 2008-07-16 14:50:30 UTC (rev 32132)
+++ grass/branches/develbranch_6/gui/wxpython/vdigit/driver.cpp 2008-07-16 14:57:50 UTC (rev 32133)
@@ -119,6 +119,34 @@
region.box.W, region.box.E, region.box.S, region.box.N);
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++) {
DrawLine(listLines->value[i]);
}
@@ -132,27 +160,67 @@
}
/**
+ \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
\param[in] line id
+
\return 1 on success
\return -1 on failure (vector object is dead, etc.)
*/
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
- bool draw; // draw object ?
-
+ bool draw; // draw object ?
wxPen *pen;
-
+
pen = NULL;
draw = false;
+ if (!dc || !Vect_line_alive (mapInfo, line))
+ return -1;
+
// read line
type = Vect_read_line (mapInfo, points, cats, line);
@@ -260,19 +328,19 @@
if (dcId > 0 && drawSegments) {
dcId = 2; // first segment
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 {
@@ -281,6 +349,7 @@
wxPoint *point_beg = (wxPoint *) pointsScreen->Item(i)->GetData();
wxPoints[i] = *point_beg;
}
+
dc->DrawLines(pointsScreen->GetCount(), wxPoints);
if (!IsSelected(line) && settings.direction.enabled) {
@@ -687,6 +756,7 @@
bool eNodeOne, unsigned long cNodeOne,
bool eNodeTwo, unsigned long cNodeTwo,
bool eVertex, unsigned long cVertex,
+ bool eArea, unsigned long cArea,
bool eDirection, unsigned long cDirection,
int lineWidth)
{
@@ -724,6 +794,9 @@
settings.vertex.enabled = eVertex;
settings.vertex.color.Set(cVertex);
+ settings.area.enabled = eArea;
+ settings.area.color.Set(cArea);
+
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-16 14:50:30 UTC (rev 32132)
+++ grass/branches/develbranch_6/gui/wxpython/vdigit/driver.h 2008-07-16 14:57:50 UTC (rev 32133)
@@ -107,6 +107,8 @@
symbol vertex;
+ symbol area;
+
symbol direction;
int lineWidth; // screen units
@@ -145,6 +147,8 @@
int DrawLineNodes(int);
int DrawDirectionArrow();
+ int DrawArea(int);
+
/* debug */
void PrintIds();
@@ -207,6 +211,7 @@
bool, unsigned long,
bool, unsigned long,
bool, unsigned long,
+ bool, unsigned long,
int);
};
More information about the grass-commit
mailing list