[GRASS-SVN] r35872 - in grass/trunk/gui/wxpython: gui_modules vdigit
svn_grass at osgeo.org
svn_grass at osgeo.org
Sat Feb 14 08:33:52 EST 2009
Author: martinl
Date: 2009-02-14 08:33:51 -0500 (Sat, 14 Feb 2009)
New Revision: 35872
Modified:
grass/trunk/gui/wxpython/gui_modules/mapdisp_window.py
grass/trunk/gui/wxpython/gui_modules/preferences.py
grass/trunk/gui/wxpython/gui_modules/vdigit.py
grass/trunk/gui/wxpython/vdigit/digit.cpp
grass/trunk/gui/wxpython/vdigit/digit.h
grass/trunk/gui/wxpython/vdigit/line.cpp
grass/trunk/gui/wxpython/vdigit/pseudodc.i
Log:
wxGUI/vdigit: add centroid to close area
fix select features by box
Modified: grass/trunk/gui/wxpython/gui_modules/mapdisp_window.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/mapdisp_window.py 2009-02-14 12:25:59 UTC (rev 35871)
+++ grass/trunk/gui/wxpython/gui_modules/mapdisp_window.py 2009-02-14 13:33:51 UTC (rev 35872)
@@ -297,11 +297,10 @@
y1 = min(coords[1],coords[3])
rwidth = x2-x1
rheight = y2-y1
- rect = wx.Rect(x1,y1,rwidth,rheight)
+ rect = wx.Rect(x1, y1, rwidth, rheight)
pdc.DrawRectangleRect(rect)
pdc.SetIdBounds(drawid, rect)
- # self.ovlcoords[drawid] = coords
-
+
elif pdctype == 'line': # draw a line on top of the map
if self.pen:
pdc.SetBrush(wx.Brush(wx.CYAN, wx.TRANSPARENT))
@@ -882,7 +881,8 @@
mousecoords = [begin[0], begin[1],
end[0], end[1]]
r = pdc.GetIdBounds(boxid)
- r.Inflate(4,4)
+ r = wx.Rect(r[0], r[1], r[2], r[3])
+ r.Inflate(4, 4)
pdc.ClearId(boxid)
self.RefreshRect(r, False)
pdc.SetId(boxid)
@@ -1900,7 +1900,9 @@
self.redrawAll = True
# add new record into atribute table
- if UserSettings.Get(group='vdigit', key="addRecord", subkey='enabled') is True:
+ if UserSettings.Get(group='vdigit', key="addRecord", subkey='enabled') and \
+ (line is True or \
+ (not line and fid > 0)):
posWindow = self.ClientToScreen((position[0] + self.dialogOffset,
position[1] + self.dialogOffset))
Modified: grass/trunk/gui/wxpython/gui_modules/preferences.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/preferences.py 2009-02-14 12:25:59 UTC (rev 35871)
+++ grass/trunk/gui/wxpython/gui_modules/preferences.py 2009-02-14 13:33:51 UTC (rev 35872)
@@ -293,6 +293,14 @@
'delRecord' : {
'enabled' : True
},
+ # add centroid to left/right area
+ 'addCentroid' : {
+ 'enabled' : False
+ },
+ # do not attach category to boundary
+ 'catBoundary' : {
+ 'enabled' : False
+ },
# query tool
'query' : {
'selection' : 0,
Modified: grass/trunk/gui/wxpython/gui_modules/vdigit.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/vdigit.py 2009-02-14 12:25:59 UTC (rev 35871)
+++ grass/trunk/gui/wxpython/gui_modules/vdigit.py 2009-02-14 13:33:51 UTC (rev 35872)
@@ -660,10 +660,16 @@
def UpdateSettings(self):
"""Update digit settigs"""
- if self.digit:
- self.digit.UpdateSettings(UserSettings.Get(group='vdigit', key='breakLines',
- subkey='enabled'))
+ if not self.digit:
+ return
+ self.digit.UpdateSettings(UserSettings.Get(group='vdigit', key='breakLines',
+ subkey='enabled'),
+ UserSettings.Get(group='vdigit', key='addCentroid',
+ subkey='enabled'),
+ UserSettings.Get(group='vdigit', key='catBoundary',
+ subkey='enabled'))
+
def __getSnapThreshold(self):
"""Get snap mode and threshold value
@@ -1423,6 +1429,26 @@
flag=wx.ALL | wx.EXPAND, border=5)
#
+ # digitize new area
+ #
+ box = wx.StaticBox (parent=panel, id=wx.ID_ANY, label=" %s " % _("Digitize new area"))
+ sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
+
+ # add centroid
+ self.addCentroid = wx.CheckBox(parent=panel, id=wx.ID_ANY,
+ label=_("Add centroid to left/right area"))
+ self.addCentroid.SetValue(UserSettings.Get(group='vdigit', key="addCentroid", subkey='enabled'))
+ sizer.Add(item=self.addCentroid, proportion=0, flag=wx.ALL | wx.EXPAND, border=1)
+
+ # attach category to boundary
+ self.catBoundary = wx.CheckBox(parent=panel, id=wx.ID_ANY,
+ label=_("Do not attach category to boundaries"))
+ self.catBoundary.SetValue(UserSettings.Get(group='vdigit', key="catBoundary", subkey='enabled'))
+ sizer.Add(item=self.catBoundary, proportion=0, flag=wx.ALL | wx.EXPAND, border=1)
+ border.Add(item=sizer, proportion=0,
+ flag=wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, border=5)
+
+ #
# delete existing record
#
box = wx.StaticBox (parent=panel, id=wx.ID_ANY, label=" %s " % _("Delete existing feature(s)"))
@@ -1626,6 +1652,12 @@
UserSettings.Set(group='vdigit', key="categoryMode", subkey='selection',
value=self.categoryMode.GetSelection())
+ # digitize new area
+ UserSettings.Set(group='vdigit', key="addCentroid", subkey='enabled',
+ value=self.addCentroid.IsChecked())
+ UserSettings.Set(group='vdigit', key="catBoundary", subkey='enabled',
+ value=self.catBoundary.IsChecked())
+
# delete existing feature
UserSettings.Set(group='vdigit', key="delRecord", subkey='enabled',
value=self.deleteRecord.IsChecked())
Modified: grass/trunk/gui/wxpython/vdigit/digit.cpp
===================================================================
--- grass/trunk/gui/wxpython/vdigit/digit.cpp 2009-02-14 12:25:59 UTC (rev 35871)
+++ grass/trunk/gui/wxpython/vdigit/digit.cpp 2009-02-14 13:33:51 UTC (rev 35872)
@@ -54,11 +54,16 @@
\brief Update digit settings
\param breakLines break lines on intersection
+ \param addCentroid add centroid to left/right area
+ \param catBoundary attach category to boundary
*/
-void Digit::UpdateSettings(bool breakLines)
+void Digit::UpdateSettings(bool breakLines,
+ bool addCentroid, bool catBoundary)
{
settings.breakLines = breakLines;
-
+ settings.addCentroid = addCentroid;
+ settings.catBoundary = !catBoundary; /* do not attach */
+
return;
}
Modified: grass/trunk/gui/wxpython/vdigit/digit.h
===================================================================
--- grass/trunk/gui/wxpython/vdigit/digit.h 2009-02-14 12:25:59 UTC (rev 35871)
+++ grass/trunk/gui/wxpython/vdigit/digit.h 2009-02-14 13:33:51 UTC (rev 35872)
@@ -24,6 +24,8 @@
/* settings */
struct _settings {
bool breakLines;
+ bool addCentroid;
+ bool catBoundary;
} settings;
/* undo/redo */
@@ -89,7 +91,8 @@
int Undo(int);
int GetUndoLevel();
- void UpdateSettings(bool);
+ void UpdateSettings(bool,
+ bool, bool);
};
#endif /* WXVDIGIT_DIGIT_H */
Modified: grass/trunk/gui/wxpython/vdigit/line.cpp
===================================================================
--- grass/trunk/gui/wxpython/vdigit/line.cpp 2009-02-14 12:25:59 UTC (rev 35871)
+++ grass/trunk/gui/wxpython/vdigit/line.cpp 2009-02-14 13:33:51 UTC (rev 35872)
@@ -31,6 +31,7 @@
\param thresh threshold value for snapping
\return fid on success
+ \return 0 for boundary if no centroid is added
\return -1 on failure
*/
int Digit::AddLine(int type, std::vector<double> coords, int layer, int cat,
@@ -42,6 +43,8 @@
int newline;
int changeset;
+ int left, right; /* left, right area */
+
struct line_pnts *Points;
struct line_cats *Cats;
@@ -53,6 +56,8 @@
return -1;
}
+ left = right = -1;
+
npoints = coords.size() / (Vect_is_3d(display->mapInfo) ? 3 : 2);
if (coords.size() != npoints * (Vect_is_3d(display->mapInfo) ? 3 : 2)) {
wxString msg;
@@ -88,7 +93,9 @@
Points = Vect_new_line_struct();
Cats = Vect_new_cats_struct();
- if (layer > 0) {
+ if (layer > 0 &&
+ (type != GV_BOUNDARY ||
+ (type == GV_BOUNDARY && settings.catBoundary))) {
Vect_cat_set(Cats, layer, cat);
if (cat > GetCategory(layer)) {
@@ -108,7 +115,8 @@
}
}
- if (type & GV_BOUNDARY) { /* close boundary */
+ if (type & GV_BOUNDARY) {
+ /* close boundary */
int last = Points->n_points-1;
if (Vect_points_distance(Points->x[0], Points->x[0], Points->z[0],
Points->x[last], Points->x[last], Points->z[last],
@@ -132,6 +140,54 @@
return -1;
}
+ if (type & GV_BOUNDARY && settings.addCentroid) {
+ double x, y;
+ struct line_pnts *bpoints;
+
+ bpoints = Vect_new_line_struct();
+
+ /* add centroid for left/right area */
+ Vect_get_line_areas(display->mapInfo, newline,
+ &left, &right);
+ /* check if area exists and has no centroid inside */
+ if (layer > 0 && (left > 0 || right > 0)) {
+ Vect_cat_set(Cats, layer, cat);
+
+ if (cat > GetCategory(layer)) {
+ SetCategory(layer, cat); /* set up max category for layer */
+ }
+ }
+
+ if (left > 0 &&
+ Vect_get_area_centroid(display->mapInfo, left) == 0) {
+ if (Vect_get_area_points(display->mapInfo, left, bpoints) > 0 &&
+ Vect_find_poly_centroid(bpoints, &x, &y) == 0) {
+ Vect_reset_line(bpoints);
+ Vect_append_point(bpoints, x, y, 0.0);
+ if (Vect_write_line(display->mapInfo, GV_CENTROID,
+ bpoints, Cats) < 0) {
+ display->WriteLineMsg();
+ return -1;
+ }
+ }
+ }
+ if (right > 0 &&
+ Vect_get_area_centroid(display->mapInfo, right) == 0) {
+ if (Vect_get_area_points(display->mapInfo, right, bpoints) > 0 &&
+ Vect_find_poly_centroid(bpoints, &x, &y) == 0) {
+ Vect_reset_line(bpoints);
+ Vect_append_point(bpoints, x, y, 0.0);
+ if (Vect_write_line(display->mapInfo, GV_CENTROID,
+ bpoints, Cats) < 0) {
+ display->WriteLineMsg();
+ return -1;
+ }
+ }
+ }
+
+ Vect_destroy_line_struct(bpoints);
+ }
+
/* register changeset */
changeset = changesets.size();
AddActionToChangeset(changeset, ADD, newline);
@@ -148,6 +204,12 @@
Vect_close(BgMap[0]);
}
+ if (type & GV_BOUNDARY &&
+ !settings.catBoundary &&
+ left < 1 && right < 1) {
+ newline = 0;
+ }
+
return newline;
}
Modified: grass/trunk/gui/wxpython/vdigit/pseudodc.i
===================================================================
--- grass/trunk/gui/wxpython/vdigit/pseudodc.i 2009-02-14 12:25:59 UTC (rev 35871)
+++ grass/trunk/gui/wxpython/vdigit/pseudodc.i 2009-02-14 13:33:51 UTC (rev 35872)
@@ -58,5 +58,8 @@
return self->FindObjects((wxCoord) x, (wxCoord) y,
(wxCoord) radius, *wxWHITE);
}
+ void DrawRectangleRect(const wxRect& rect) {
+ return self->DrawRectangle(rect);
+ }
}
};
More information about the grass-commit
mailing list