[GRASS-SVN] r29934 - in grass/trunk/gui/wxpython: gui_modules vdigit
svn_grass at osgeo.org
svn_grass at osgeo.org
Sat Feb 2 16:21:26 EST 2008
Author: martinl
Date: 2008-02-02 16:21:26 -0500 (Sat, 02 Feb 2008)
New Revision: 29934
Modified:
grass/trunk/gui/wxpython/gui_modules/digit.py
grass/trunk/gui/wxpython/gui_modules/mapdisp.py
grass/trunk/gui/wxpython/vdigit/dig_types.i
grass/trunk/gui/wxpython/vdigit/driver.cpp
grass/trunk/gui/wxpython/vdigit/driver.h
Log:
wx/vdigit: Fix selecting features by point/box.
Selecting features can be filter out by type (point, line, centroid, boundary), see settings dialog (query tool tab).
Modified: grass/trunk/gui/wxpython/gui_modules/digit.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/digit.py 2008-02-02 18:49:03 UTC (rev 29933)
+++ grass/trunk/gui/wxpython/gui_modules/digit.py 2008-02-02 21:21:26 UTC (rev 29934)
@@ -59,6 +59,8 @@
#
USEVEDIT = True
+GV_LINES = vdigit.GV_LINES
+
class AbstractDigit:
"""
Abstract digitization class
@@ -115,6 +117,12 @@
self.settings["query"] = ("length", True) # name, select by box
self.settings["queryLength"] = ("shorter than", 0) # gt or lt, threshold
self.settings["queryDangle"] = ("shorter than", 0)
+ # select feature (point, line, centroid, boundary)
+ self.settings["selectFeature"] = {}
+ self.settings["selectFeature"]["point"] = {'id': None, 'val': True}
+ self.settings["selectFeature"]["line"] = {'id': None, 'val': True}
+ self.settings["selectFeature"]["centroid"] = {'id': None, 'val': True}
+ self.settings["selectFeature"]["boundary"] = {'id': None, 'val': True}
else:
self.settings = settings
@@ -199,6 +207,21 @@
return thresh
+ def GetSelectType(self):
+ """Get type(s) to be selected
+
+ Used by SelectLinesByBox() and SelectLinesByPoint()"""
+
+ type = 0
+ for feature in (('point', vdigit.GV_POINT),
+ ('line', vdigit.GV_LINE),
+ ('centroid', vdigit.GV_CENTROID),
+ ('boundary', vdigit.GV_BOUNDARY)):
+ if self.settings['selectFeature'][feature[0]]['val'] is True:
+ type |= feature[1]
+
+ return type
+
class VEdit(AbstractDigit):
"""
Prototype of digitization class based on v.edit command
@@ -1107,7 +1130,7 @@
return nlines
- def SelectLinesByBox(self, begin, end, type=None):
+ def SelectLinesByBox(self, begin, end, type=0):
"""Select vector features by given bounding box.
If type is given, only vector features of given type are selected.
@@ -1118,13 +1141,15 @@
x1, y1 = begin
x2, y2 = end
- nselected = self.__display.SelectLinesByBox(x1, y1, x2, y2)
+ nselected = self.__display.SelectLinesByBox(x1, y1, -1.0 * vdigit.PORT_DOUBLE_MAX,
+ x2, y2, vdigit.PORT_DOUBLE_MAX,
+ type)
Debug.msg(4, "CDisplayDriver.SelectLinesByBox(): selected=%d" % \
nselected)
return nselected
- def SelectLineByPoint(self, point, type=None):
+ def SelectLineByPoint(self, point, type=0):
"""Select vector feature by coordinates of click point (in given threshold).
If type is given, only vector features of given type are selected.
@@ -1132,16 +1157,9 @@
@param point click coordinates (bounding box given by threshold)
@param type select only objects of given type
"""
- ftype = -1 # all types
- if type:
- if type == "point":
- ftype = 0
- else:
- ftype = 1 # line
-
- pointOnLine = self.__display.SelectLineByPoint(point[0], point[1],
+ pointOnLine = self.__display.SelectLineByPoint(point[0], point[1], 0.0,
self.GetThreshold(),
- ftype);
+ type, 0); # without_z
if len(pointOnLine) > 0:
Debug.msg(4, "CDisplayDriver.SelectLineByPoint(): pointOnLine=%f,%f" % \
@@ -1509,7 +1527,10 @@
notebook.AddPage(page=panel, text=_("Query tool"))
border = wx.BoxSizer(wx.VERTICAL)
-
+
+ #
+ # query tool box
+ #
box = wx.StaticBox (parent=panel, id=wx.ID_ANY, label=" %s " % _("Choose query tool"))
sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
@@ -1577,6 +1598,21 @@
border.Add(item=sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
+ #
+ # select box
+ #
+ box = wx.StaticBox (parent=panel, id=wx.ID_ANY, label=" %s " % _("Select vector features"))
+ sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
+ for feature in ('point', 'line',
+ 'centroid', 'boundary'):
+ chkbox = wx.CheckBox(parent=panel, label=feature)
+ settings['selectFeature'][feature]['id'] = chkbox.GetId()
+ chkbox.SetValue(settings['selectFeature'][feature]['val'])
+ sizer.Add(item=chkbox, proportion=0,
+ flag=wx.EXPAND | wx.ALL, border=3)
+
+ border.Add(item=sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
+
panel.SetSizer(border)
return panel
@@ -1734,6 +1770,12 @@
self.parent.digit.settings["queryDangle"] = (self.queryDangleSL.GetStringSelection(),
int(self.queryDangleValue.GetValue()))
+ # select features
+ for feature in ('point', 'line',
+ 'centroid', 'boundary'):
+ self.parent.digit.settings['selectFeature'][feature]['val'] = \
+ self.FindWindowById(self.parent.digit.settings["selectFeature"][feature]['id']).IsChecked()
+
# update driver settings
self.parent.digit.driver.UpdateSettings()
Modified: grass/trunk/gui/wxpython/gui_modules/mapdisp.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/mapdisp.py 2008-02-02 18:49:03 UTC (rev 29933)
+++ grass/trunk/gui/wxpython/gui_modules/mapdisp.py 2008-02-02 21:21:26 UTC (rev 29934)
@@ -67,6 +67,7 @@
from digit import Digit as Digit
from digit import DigitCategoryDialog as DigitCategoryDialog
from digit import DigitZBulkDialog as DigitZBulkDialog
+from digit import GV_LINES as Digit_Lines_Type
from debug import Debug as Debug
from icon import Icons as Icons
@@ -1005,9 +1006,8 @@
pos=posWindow,
title=_("Update categories"))
else:
- if digitClass.driver.SelectLineByPoint(coords) is not None:
- print '#', digitClass.driver.GetSelected()[0], \
- digitClass.GetLineCats()
+ if digitClass.driver.SelectLineByPoint(coords,
+ digitClass.GetSelectType()) is not None:
digitToolbar.categoryDialog = DigitCategoryDialog(parent=self,
map=map,
cats=digitClass.GetLineCats(),
@@ -1064,7 +1064,8 @@
if len(digitClass.driver.GetSelected()) > 1:
# if two line selected -> reset
digitClass.driver.SetSelected([])
- digitClass.driver.SelectLineByPoint(self.Pixel2Cell(self.mouse['begin']))
+ digitClass.driver.SelectLineByPoint(self.Pixel2Cell(self.mouse['begin']),
+ digitClass.GetSelectType())
else:
# get decoration id
@@ -1123,7 +1124,6 @@
pass
elif self.mouse["use"] == "pointer" and self.gismanager.georectifying:
self.SetCursor(self.parent.cursors["cross"])
- print self.Pixel2Cell(self.mouse['end'])
self.DrawCross(pdc=self.pdcTmp, coords=self.mouse['end'],
size=5)
@@ -1148,7 +1148,7 @@
# -> delete line || move line || move vertex
if digitToolbar.action in ["moveVertex", "editLine"]:
if len(digitClass.driver.GetSelected()) == 0:
- nselected = digitClass.driver.SelectLineByPoint(pos1, type="line")
+ nselected = digitClass.driver.SelectLineByPoint(pos1, type=Digit_Lines_Type)
if digitToolbar.action == "editLine":
self.UpdateMap(render=False)
selVertex = digitClass.driver.GetSelectedVertex(pos1)[0]
@@ -1171,7 +1171,7 @@
elif digitToolbar.action == "copyCats":
if not hasattr(self, "copyCatsIds"):
# collect categories
- nselected = digitClass.driver.SelectLineByPoint(pos1, type="line")
+ nselected = digitClass.driver.SelectLineByPoint(pos1, type=Digit_Lines_Type)
if nselected:
qdist = 10.0 * ((self.Map.region['e'] - self.Map.region['w']) / \
self.Map.width)
@@ -1190,7 +1190,8 @@
# collect ids
digitClass.driver.SetSelected([])
# return number of selected features
- nselected = digitClass.driver.SelectLinesByBox(pos1, pos2)
+ nselected = digitClass.driver.SelectLinesByBox(pos1, pos2,
+ digitClass.GetSelectType())
if nselected > 0:
self.copyCatsIds = digitClass.driver.GetSelected()
@@ -1202,18 +1203,19 @@
else:
# -> moveLine || deleteLine, etc. (select by point/box)
- if digitClass.driver.SelectLineByPoint(pos1) is not None:
- nselected = 1
- else:
- nselected = digitClass.driver.SelectLinesByBox(pos1, pos2)
-
+ nselected = digitClass.driver.SelectLinesByBox(pos1, pos2,
+ digitClass.GetSelectType())
+ if nselected == 0:
+ if digitClass.driver.SelectLineByPoint(pos1,
+ digitClass.GetSelectType()) is not None:
+ nselected = 1
+
if nselected > 0:
if digitToolbar.action in ["moveLine", "moveVertex"]:
# get pseudoDC id of objects which should be redrawn
if digitToolbar.action == "moveLine":
# -> move line
self.moveIds = digitClass.driver.GetSelected(grassId=False)
- print self.moveIds, nselected
elif digitToolbar.action == "moveVertex":
# -> move vertex
@@ -1230,7 +1232,7 @@
elif digitToolbar.action in ["splitLine", "addVertex", "removeVertex"]:
pointOnLine = digitClass.driver.SelectLineByPoint(pos1,
- type="line")
+ type=Digit_Lines_Type)
if pointOnLine:
self.UpdateMap(render=False) # highlight object
if digitToolbar.action in ["splitLine", "addVertex"]:
@@ -1247,7 +1249,8 @@
elif digitToolbar.action == "copyLine":
if digitClass.settings['backgroundMap'] == '':
# no background map -> copy from current vector map layer
- nselected = digitClass.driver.SelectLinesByBox(pos1, pos2)
+ nselected = digitClass.driver.SelectLinesByBox(pos1, pos2,
+ digitClass.GetSelectType())
if nselected > 0:
# highlight selected features
@@ -1281,7 +1284,8 @@
# select lines to be labeled
pos1 = self.polycoords[0]
pos2 = self.polycoords[1]
- nselected = digitClass.driver.SelectLinesByBox(pos1, pos2)
+ nselected = digitClass.driver.SelectLinesByBox(pos1, pos2,
+ digitClass.GetSelectType())
if nselected > 0:
# highlight selected features
Modified: grass/trunk/gui/wxpython/vdigit/dig_types.i
===================================================================
--- grass/trunk/gui/wxpython/vdigit/dig_types.i 2008-02-02 18:49:03 UTC (rev 29933)
+++ grass/trunk/gui/wxpython/vdigit/dig_types.i 2008-02-02 21:21:26 UTC (rev 29934)
@@ -12,6 +12,8 @@
#define GV_POINTS (GV_POINT | GV_CENTROID )
#define GV_LINES (GV_LINE | GV_BOUNDARY )
+#define PORT_DOUBLE_MAX 1.7976931348623157e+308
+
/* extracted from vector/v.edit/lib/vedit.h */
#define NO_SNAP 0 /* snapping disabled */
Modified: grass/trunk/gui/wxpython/vdigit/driver.cpp
===================================================================
--- grass/trunk/gui/wxpython/vdigit/driver.cpp 2008-02-02 18:49:03 UTC (rev 29933)
+++ grass/trunk/gui/wxpython/vdigit/driver.cpp 2008-02-02 21:21:26 UTC (rev 29934)
@@ -722,42 +722,40 @@
If line id is already in the list of selected lines, then it will
be excluded from this list.
- \param[in] x1,y1,x2,y2 corners coordinates of bounding box
+ \param[in] x1,y1,z1,x2,y2,z3 bounding box definition
+ \param[in] type feature type
+
\return number of selected features
\return -1 on error
*/
-int DisplayDriver::SelectLinesByBox(double x1, double y1, double x2, double y2)
+int DisplayDriver::SelectLinesByBox(double x1, double y1, double z1,
+ double x2, double y2, double z2,
+ int type)
{
if (!mapInfo)
return -1;
- int type, line;
- double dx, dy;
+ int line;
struct ilist *list;
struct line_pnts *bbox;
drawSegments = false;
- type = -1; // all types
-
list = Vect_new_list();
bbox = Vect_new_line_struct();
- dx = std::fabs(x2 - x1);
- dy = std::fabs(y2 - y1);
+ Vect_append_point(bbox, x1, y1, z1);
+ Vect_append_point(bbox, x2, y1, z2);
+ Vect_append_point(bbox, x2, y2, z1);
+ Vect_append_point(bbox, x1, y2, z2);
+ Vect_append_point(bbox, x1, y1, z1);
- Vect_append_point(bbox, x1, y1, -PORT_DOUBLE_MAX);
- Vect_append_point(bbox, x2, y1, PORT_DOUBLE_MAX);
- Vect_append_point(bbox, x2, y2, -PORT_DOUBLE_MAX);
- Vect_append_point(bbox, x1, y2, PORT_DOUBLE_MAX);
- Vect_append_point(bbox, x1, y1, -PORT_DOUBLE_MAX);
-
Vect_select_lines_by_polygon(mapInfo, bbox,
- 0, NULL,
+ 0, NULL, /* isles */
type, list);
-
+
for (int i = 0; i < list->n_values; i++) {
line = list->value[i];
if (!IsSelected(line)) {
@@ -778,7 +776,8 @@
Vect_destroy_list(list);
// return selected.size();
- return selected->n_values;
+ // return selected->n_values;
+ return list->n_values;
}
/**
@@ -790,12 +789,12 @@
\param[in] x,y point of searching
\param[in] thresh threshold value where to search
- \param[in] onlyType select vector object of given type
+ \param[in] type select vector object of given type
\return point on line if line found
*/
-std::vector<double> DisplayDriver::SelectLineByPoint(double x, double y, double thresh,
- int type)
+std::vector<double> DisplayDriver::SelectLineByPoint(double x, double y, double z,
+ double thresh, int type, int with_z)
{
long int line;
int ftype;
@@ -803,28 +802,28 @@
std::vector<double> p;
- if (type == -1) {
- ftype = GV_POINTS | GV_LINES;
- }
- else if (type == 0) {
- ftype = GV_POINTS;
- }
- else if (type == 1) {
- ftype = GV_LINES;
- }
+ line = Vect_find_line(mapInfo, x, y, z,
+ type, thresh, with_z, 0);
- line = Vect_find_line(mapInfo, x, y, 0.0,
- ftype, thresh, 0, 0);
-
if (line > 0) {
- // selected.push_back(line);
- Vect_list_append(selected, line);
+ if (!IsSelected(line)) {
+ // selected.push_back(line);
+ Vect_list_append(selected, line);
+ }
+ else {
+ // selected.erase(GetSelectedIter(line));
+ Vect_list_delete(selected, line);
+ }
+
type = Vect_read_line (mapInfo, points, cats, line);
- Vect_line_distance (points, x, y, 0.0, WITHOUT_Z,
+ Vect_line_distance (points, x, y, z, with_z,
&px, &py, &pz,
NULL, NULL, NULL);
p.push_back(px);
p.push_back(py);
+ if (with_z) {
+ p.push_back(pz);
+ }
}
drawSegments = true;
Modified: grass/trunk/gui/wxpython/vdigit/driver.h
===================================================================
--- grass/trunk/gui/wxpython/vdigit/driver.h 2008-02-02 18:49:03 UTC (rev 29933)
+++ grass/trunk/gui/wxpython/vdigit/driver.h 2008-02-02 21:21:26 UTC (rev 29934)
@@ -158,9 +158,9 @@
int DrawMap(bool);
/* select */
- int SelectLinesByBox(double, double, double, double);
+ int SelectLinesByBox(double, double, double, double, double, double, int);
std::vector<double> SelectLineByPoint(double, double, double,
- int);
+ double, int, int);
std::vector<int> GetSelected(bool);
int SetSelected(std::vector<int>);
More information about the grass-commit
mailing list