[GRASS-SVN] r29710 - grass/trunk/gui/wxpython/vdigit

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Jan 14 17:16:45 EST 2008


Author: martinl
Date: 2008-01-14 17:16:45 -0500 (Mon, 14 Jan 2008)
New Revision: 29710

Added:
   grass/trunk/gui/wxpython/vdigit/dig_types.i
   grass/trunk/gui/wxpython/vdigit/vertex.cpp
Modified:
   grass/trunk/gui/wxpython/vdigit/Makefile.in
   grass/trunk/gui/wxpython/vdigit/cats.cpp
   grass/trunk/gui/wxpython/vdigit/digit.cpp
   grass/trunk/gui/wxpython/vdigit/digit.h
   grass/trunk/gui/wxpython/vdigit/driver.cpp
   grass/trunk/gui/wxpython/vdigit/driver.h
   grass/trunk/gui/wxpython/vdigit/line.cpp
Log:
wxGUI: vdigit interface upgraded, some new functions added. Rules for Makefile rewriten.

Modified: grass/trunk/gui/wxpython/vdigit/Makefile.in
===================================================================
--- grass/trunk/gui/wxpython/vdigit/Makefile.in	2008-01-14 15:59:28 UTC (rev 29709)
+++ grass/trunk/gui/wxpython/vdigit/Makefile.in	2008-01-14 22:16:45 UTC (rev 29710)
@@ -7,42 +7,39 @@
 MODULE_TOPDIR = ../../..
 
 include $(MODULE_TOPDIR)/include/Make/Lib.make
-include $(MODULE_TOPDIR)/include/Make/Doxygen.make
 
 SWIG=swig
 
-CFLAGS=-c -fpic -I/usr/include/python$(PYTHONVERSION) -I./ -I$(ARCH_DISTDIR)/include `wx-config --cxxflags` `gdal-config --cflags`
+CXXFLAGS=-c -fpic -I$(ARCH_DISTDIR)/include  -I/usr/include/python$(PYTHONVERSION) `wx-config --cxxflags`
 
-LDFLAGS=-shared -fpic -L$(ARCH_LIBDIR) -lgrass_vect -lgrass_gis `wx-config --libs` -L./ -lgdi
+LDFLAGS=-shared -fpic -L$(ARCH_LIBDIR) $(VECTLIB) $(GISLIB) $(GDALLIBS) $(VEDITLIB) `wx-config --libs` -lgdi
 
+LOCAL_HEADERS=digit.h driver.h
+SOURCES=driver.cpp digit.cpp cats.cpp line.cpp vertex.cpp
+
+OBJARCH=OBJ.$(ARCH)
+OBJ := $(patsubst %.cpp, $(OBJARCH)/%.o, $(SOURCES))
+
 default: grass6_wxvdigit.so
 
 clean:
-	-rm -f *.o _grass6_wxvdigit.so grass6_wxvdigit_wrap.cxx grass6_wxvdigit.py grass6_wxvdigit.i grass6_wxvdigit.pyc	 
+	-rm -rf $(OBJARCH) _grass6_wxvdigit.so grass6_wxvdigit_wrap.cxx grass6_wxvdigit.py grass6_wxvdigit.i grass6_wxvdigit.pyc	 
 
 grass6_wxvdigit.i:
 	cat ./digit.i > grass6_wxvdigit.i
-	echo "/* auto-generate swig typedef file (with some GRASS functions removed) */" >> grass6_wxvdigit.i
+	cat ./dig_types.i >> grass6_wxvdigit.i
+	echo "/* auto-generate swig typedef file */" >> grass6_wxvdigit.i
 	cat ./driver.h >> grass6_wxvdigit.i
 	cat ./digit.h >> grass6_wxvdigit.i
 
 grass6_wxvdigit_wrap.cxx: grass6_wxvdigit.i
 	$(SWIG) -c++ -python -shadow $<
 
-grass6_wxvdigit_wrap.o: grass6_wxvdigit_wrap.cxx
-	$(CXX) $(CFLAGS) $(INCLUDE_DIRS) $<
+$(OBJARCH)/grass6_wxvdigit_wrap.o: grass6_wxvdigit_wrap.cxx $(OBJARCH)
+	$(CXX) -c $(CXXFLAGS) $(INCLUDE_DIRS) $< -o $@
 
-driver.o: driver.cpp driver.h
-	$(CXX) $(CFLAGS) $(INCLUDE_DIRS) $<
+$(OBJARCH)/%.o: %.cpp $(LOCAL_HEADERS)
+	$(CXX) -c $(CXXFLAGS) $(INCLUDE_DIRS) $< -o $@
 
-digit.o: digit.cpp digit.h
-	$(CXX) $(CFLAGS) $(INCLUDE_DIRS) $<
-
-cats.o: cats.cpp digit.h
-	$(CXX) $(CFLAGS) $(INCLUDE_DIRS) $<
-
-line.o: line.cpp digit.h
-	$(CXX) $(CFLAGS) $(INCLUDE_DIRS) $<
-
-grass6_wxvdigit.so: grass6_wxvdigit_wrap.o driver.o digit.o cats.o line.o
-	$(CXX) $(LDFLAGS) grass6_wxvdigit_wrap.o driver.o digit.o cats.o line.o -o _grass6_wxvdigit.so
+grass6_wxvdigit.so: $(OBJARCH)/grass6_wxvdigit_wrap.o $(OBJ)
+	$(CXX) $(LDFLAGS) $(OBJARCH)/grass6_wxvdigit_wrap.o $(OBJ) -o _grass6_wxvdigit.so

Modified: grass/trunk/gui/wxpython/vdigit/cats.cpp
===================================================================
--- grass/trunk/gui/wxpython/vdigit/cats.cpp	2008-01-14 15:59:28 UTC (rev 29709)
+++ grass/trunk/gui/wxpython/vdigit/cats.cpp	2008-01-14 22:16:45 UTC (rev 29710)
@@ -7,9 +7,10 @@
    License (>=v2). Read the file COPYING that comes with GRASS
    for details.
 
-   \author (C) by The GRASS development team
-   Martin Landa <landa.martin gmail.com>
+   (C) 2008 by The GRASS development team
 
+   \author Martin Landa <landa.martin gmail.com>
+
    \date 2008 
 */
 
@@ -105,3 +106,18 @@
     return old_cat;
 }
 
+/**
+   \brief Copy categories from one vector feature to other
+
+   \param cats  list of layer/category to be copied			       
+   \param ids   list of line ids where to copy categories
+
+   \return number of modified features
+   \return -1 on error
+*/
+int Digit::CopyCats(std::vector<std::vector<int> > cats, std::vector<int> ids)
+{
+  /* TODO */
+
+  return 0;
+}

Added: grass/trunk/gui/wxpython/vdigit/dig_types.i
===================================================================
--- grass/trunk/gui/wxpython/vdigit/dig_types.i	                        (rev 0)
+++ grass/trunk/gui/wxpython/vdigit/dig_types.i	2008-01-14 22:16:45 UTC (rev 29710)
@@ -0,0 +1,19 @@
+/* extracted from include/vect/dig_defines.h */
+
+#define GV_POINT      0x01
+#define GV_LINE       0x02
+#define GV_BOUNDARY   0x04
+#define GV_CENTROID   0x08
+#define GV_FACE       0x10
+#define GV_KERNEL     0x20
+#define GV_AREA       0x40
+#define GV_VOLUME     0x80
+
+#define GV_POINTS (GV_POINT | GV_CENTROID )
+#define GV_LINES (GV_LINE | GV_BOUNDARY )
+
+/* extracted from vector/v.edit/lib/vedit.h */
+
+#define NO_SNAP    0 /* snapping disabled */
+#define SNAP       1 /* snapping enabled for nodes */
+#define SNAPVERTEX 2 /* snapping enabled for vertex also */

Modified: grass/trunk/gui/wxpython/vdigit/digit.cpp
===================================================================
--- grass/trunk/gui/wxpython/vdigit/digit.cpp	2008-01-14 15:59:28 UTC (rev 29709)
+++ grass/trunk/gui/wxpython/vdigit/digit.cpp	2008-01-14 22:16:45 UTC (rev 29710)
@@ -29,4 +29,7 @@
     if (display->mapInfo) {
 	InitCats();
     }
+
+    // avoid GUI crash
+    // Vect_set_fatal_error(GV_FATAL_PRINT);
 }

Modified: grass/trunk/gui/wxpython/vdigit/digit.h
===================================================================
--- grass/trunk/gui/wxpython/vdigit/digit.h	2008-01-14 15:59:28 UTC (rev 29709)
+++ grass/trunk/gui/wxpython/vdigit/digit.h	2008-01-14 22:16:45 UTC (rev 29710)
@@ -19,9 +19,32 @@
 
     int InitCats();
 
-    int AddLine(int, std::vector<double>, bool, int, int);
-    int DeleteSelectedLines();
+    int AddLine(int, std::vector<double>, int, int,
+		const char*, int, double);
+    int RewriteLine(int, std::vector<double>);
+    int SplitLine(double, double, double,
+		  double);
 
+    int DeleteLines();
+    int MoveLines(double, double, double,
+		  int, double);
+    int FlipLines();
+    int MergeLines();
+    int BreakLines();
+    int SnapLines(double);
+    int ConnectLines(double);
+    int ZBulkLabeling(double, double, double, double,
+		      double, double);
+    int CopyLines(std::vector<int>, const char*);
+
+    int MoveVertex(double, double, double,
+		   double, double, double,
+		   int, double);
+    int ModifyLineVertex(int, double, double, double,
+			 double);
+
+    int CopyCats(std::vector<std::vector<int> >, std::vector<int>);
+
     int GetCategory(int);
 
 };

Modified: grass/trunk/gui/wxpython/vdigit/driver.cpp
===================================================================
--- grass/trunk/gui/wxpython/vdigit/driver.cpp	2008-01-14 15:59:28 UTC (rev 29709)
+++ grass/trunk/gui/wxpython/vdigit/driver.cpp	2008-01-14 22:16:45 UTC (rev 29710)
@@ -35,11 +35,17 @@
 
     dc = (wxPseudoDC *) device;
 
-    points       = Vect_new_line_struct();
+    points = Vect_new_line_struct();
     pointsScreen = new wxList();
-    cats         = Vect_new_cats_struct();
+    cats = Vect_new_cats_struct();
+    
+    selected = Vect_new_list();
 
     drawSegments = false;
+
+    // avoid GUI crash
+    // Vect_set_fatal_error(GV_FATAL_PRINT);
+    // G_set_error_routine(print_error);
 }
 
 /**
@@ -59,6 +65,7 @@
     Vect_destroy_line_struct(points);
     delete pointsScreen;
     Vect_destroy_cats_struct(cats);
+    Vect_destroy_list(selected);
 }
 
 /**
@@ -97,35 +104,16 @@
 
     /* nlines = Vect_get_num_lines(mapInfo); */
 
-    //Vect_build_partial(mapInfo, GV_BUILD_NONE, stderr);
-    //Vect_build(mapInfo, stderr);
-
     Vect_get_map_box(mapInfo, &mapBox);
 
     // draw lines inside of current display region
     nlines = Vect_select_lines_by_box(mapInfo, &(region.box),
      				      GV_POINTS | GV_LINES, // fixme
 				      listLines);
-    /*
-    nlines = Vect_select_lines_by_box(mapInfo, &mapBox,
-				      GV_POINTS | GV_LINES, // fixme
- 				      listLines);
 
-    for (int i = 0; i < listLines->n_values; i++) {
-	DrawLine(listLines->value[i]);
-    }
-    */
+    G_debug(3, "driver.DrawMap(): region: w=%f, e=%f, s=%f, n=%f",
+	    region.box.W, region.box.E, region.box.S, region.box.N);
 
-#ifdef DEBUG
-    std::cerr.flags(std::ios_base::fixed);
-    std::cerr << "region: W=" << region.box.W
-	      << "; E=" << region.box.E
-	      << "; S=" << region.box.S
-	      << "; N=" << region.box.N << std::endl;
-
-    std::cerr << "-> nlines=" << nlines << std::endl;
-#endif
-
     bool inBox;
     dc->BeginDrawing();
     for (int i = 0; i < listLines->n_values; i++) {
@@ -133,9 +121,7 @@
     }
     dc->EndDrawing();
 
-#ifdef DEBUG
-    PrintIds();
-#endif
+    // PrintIds();
 
     Vect_destroy_list(listLines);
 
@@ -578,20 +564,6 @@
     region.map_width  = map_width;
     region.map_height = map_height;
 
-#ifdef DEBUG
-    std::cerr << "region: n=" << north
-	      << "; s=" << south
-	      << "; e=" << east
-	      << "; w=" << west
-	      << "; ns_res=" << ns_res
-	      << "; ew_res=" << ew_res
-	      << "; center_easting=" << center_easting
-	      << "; center_northing=" << center_northing
-	      << "; map_width=" << map_width
-	      << "; map_height=" << map_height
-	      << std::endl;
-#endif
-
     // calculate real region
     region.map_res = (region.ew_res > region.ns_res) ? region.ew_res : region.ns_res;
 
@@ -643,8 +615,7 @@
 				   bool eNodeOne,     unsigned long cNodeOne,
 				   bool eNodeTwo,     unsigned long cNodeTwo,
 				   bool eVertex,      unsigned long cVertex,
-				   int lineWidth,
-				   double threshold)
+				   int lineWidth)
 {
     settings.highlight.Set(highlight);
 
@@ -678,7 +649,6 @@
     settings.vertex.color.Set(cVertex);
 
     settings.lineWidth = lineWidth;
-    settings.threshold = threshold;    
 }
 
 /**
@@ -692,16 +662,6 @@
 */
 void DisplayDriver::PrintIds()
 {
-    /*
-      for (ids_map::const_iterator i = ids.begin(), e = ids.end();
-      i != e; ++i) {
-      std::cerr << "line=" << i->first << ": "
-      << "npoints=" << i->second.npoints
-      << " startId=" << i->second.startId
-      << std::endl;
-      }
-    */
-
     std::cerr << "topology.highlight: " << topology.highlight << std::endl;
 
     std::cerr << "topology.point: " << topology.point << std::endl;
@@ -734,9 +694,10 @@
       topology.vertex * 2 << std::endl;
 
     std::cerr << "selected: ";
-    for (std::vector<int>::const_iterator i = selected.begin(), e = selected.end();
-	 i != e; ++i)
-	std::cerr << *i << " ";
+
+    for (int i = 0; i < selected->n_values; i++) {
+	std::cerr << selected->value[i] << " ";
+    }
     std::cerr << std::endl;
 
     return;
@@ -785,21 +746,24 @@
     for (int i = 0; i < list->n_values; i++) {
 	line = list->value[i];
 	if (!IsSelected(line)) {
-	    selected.push_back(line);
+	    // selected.push_back(line);
+	    Vect_list_append(selected, line);
 	}
 	else {
-	    selected.erase(GetSelectedIter(line));
+	    // selected.erase(GetSelectedIter(line));
+	    Vect_list_delete(selected, line);
 	}
     }
 
     // remove all duplicate ids
-    sort(selected.begin(), selected.end());
-    selected.erase(unique(selected.begin(), selected.end()), selected.end());
+    // sort(selected.begin(), selected.end());
+    // selected.erase(unique(selected.begin(), selected.end()), selected.end());
 
     Vect_destroy_line_struct(bbox);
     Vect_destroy_list(list);
 
-    return selected.size();
+    // return selected.size();
+    return selected->n_values;
 }
 
 /**
@@ -838,7 +802,8 @@
 			  ftype, thresh, 0, 0);
 
     if (line > 0) {
-	selected.push_back(line);
+	// selected.push_back(line);
+	Vect_list_append(selected, line);
 	type = Vect_read_line (mapInfo, points, cats, line);
 	Vect_line_distance (points, x, y, 0.0, WITHOUT_Z,
 			    &px, &py, &pz,
@@ -862,7 +827,8 @@
 */
 bool DisplayDriver::IsSelected(int line)
 {
-    if (GetSelectedIter(line) != selected.end())
+    // if (GetSelectedIter(line) != selected.end())
+    if (Vect_val_in_list(selected, line))
 	return true;
 
     return false;
@@ -876,6 +842,7 @@
    \return item iterator
    \return selected.end() if object is not selected
 */
+/*
 std::vector<int>::iterator DisplayDriver::GetSelectedIter(int line)
 {
     for(std::vector<int>::iterator i = selected.begin(), e = selected.end();
@@ -886,7 +853,7 @@
 
     return selected.end();
 }
-
+*/
 /**
    \brief Get ids of selected objects
 
@@ -898,7 +865,7 @@
 std::vector<int> DisplayDriver::GetSelected(bool grassId)
 {
     if (grassId)
-	return selected;
+	return ListToVector(selected);
 
     std::vector<int> dc_ids;
     long int line;
@@ -908,7 +875,7 @@
     }
     else {
 	int npoints;
-	Vect_read_line(mapInfo, points, NULL, selected[0]);
+	Vect_read_line(mapInfo, points, NULL, selected->value[0]);
 	npoints = points->n_points;
 	for (int i = 1; i < 2 * npoints; i++) {
 	  dc_ids.push_back(i);
@@ -955,9 +922,10 @@
 */
 int DisplayDriver::SetSelected(std::vector<int> id)
 {
-    selected = id;
+    // selected = id;
+    VectorToList(selected, id);
 
-    if (selected.size() <= 0)
+    if (selected->n_values <= 0)
 	drawSegments = false;
 
     return 1;
@@ -988,11 +956,11 @@
     std::vector<int> returnId;
 
     // only one object can be selected
-    if (selected.size() != 1 || !drawSegments) 
+    if (selected->n_values != 1 || !drawSegments) 
 	return returnId;
 
     startId = 1;
-    line = selected[0];
+    line = selected->value[0];
 
     type = Vect_read_line (mapInfo, points, cats, line);
         
@@ -1076,3 +1044,61 @@
 
     return;
 }
+
+/**
+   \brief Convert vect list to std::vector
+
+   \param list vect list
+
+   \return std::vector
+*/
+std::vector<int> DisplayDriver::ListToVector(struct ilist *list)
+{
+    std::vector<int> vect;
+
+    if (!list)
+	return vect;
+
+    for (int i = 0; i < list->n_values; i++) {
+	vect.push_back(list->value[i]);
+    }
+
+    return vect;
+}
+
+/**
+   \brief Convert std::vector to vect list
+
+   \param list vect list
+   \param vec  std::vector instance
+
+   \return number of items
+   \return -1 on error
+*/
+int DisplayDriver::VectorToList(struct ilist *list, const std::vector<int>& vec)
+{
+    if (!list)
+	return -1;
+
+    Vect_reset_list(list);
+
+    for (std::vector<int>::const_iterator i = vec.begin(), e = vec.end();
+	 i != e; ++i) {
+	Vect_list_append(list, *i);
+    }
+
+    return list->n_values;
+}
+
+/**
+   \brief Error messages handling 
+
+   \param msg message
+   \param type type message (MSG, WARN, ERR)
+
+   \return 0
+*/
+int print_error(const char *msg, int type)
+{
+    return 0;
+}

Modified: grass/trunk/gui/wxpython/vdigit/driver.h
===================================================================
--- grass/trunk/gui/wxpython/vdigit/driver.h	2008-01-14 15:59:28 UTC (rev 29709)
+++ grass/trunk/gui/wxpython/vdigit/driver.h	2008-01-14 22:16:45 UTC (rev 29710)
@@ -28,8 +28,6 @@
 #include <grass/Vect.h>
 }
 
-// #define DEBUG
-
 class DisplayDriver
 {
 private:
@@ -56,7 +54,10 @@
     ids_map ids; // gId : {dcIds, ...}
     */
 
-    std::vector<int> selected; // list of selected features (gId)
+    // list of selected features (gId)
+    // std::vector<int> selected; 
+    struct ilist *selected;
+
     bool drawSegments;         // draw segments of selected line
 
     struct Map_info  *mapInfo;
@@ -105,8 +106,6 @@
 	symbol vertex;
 
 	int lineWidth;    // screen units 
-
-	double threshold; // threshold value (map units)
     } settings;
 
     struct _topology {
@@ -143,7 +142,9 @@
 
     /* select feature */
     bool IsSelected(int line);
-    std::vector<int>::iterator GetSelectedIter(int line);
+    // std::vector<int>::iterator GetSelectedIter(int line);
+    std::vector<int> ListToVector(struct ilist *);
+    int VectorToList(struct ilist *, const std::vector<int>&);
 
     void ResetTopology();
 
@@ -189,8 +190,9 @@
 			bool, unsigned long,
 			bool, unsigned long,
 			bool, unsigned long,
-			int,
-			double);
+			int);
 };
 
+int print_error(const char *, int);
+
 #endif /* __DRIVER_H__ */

Modified: grass/trunk/gui/wxpython/vdigit/line.cpp
===================================================================
--- grass/trunk/gui/wxpython/vdigit/line.cpp	2008-01-14 15:59:28 UTC (rev 29709)
+++ grass/trunk/gui/wxpython/vdigit/line.cpp	2008-01-14 22:16:45 UTC (rev 29710)
@@ -7,75 +7,56 @@
    License (>=v2). Read the file COPYING that comes with GRASS
    for details.
 
-   \author (C) by The GRASS development team
-   Martin Landa <landa.martin gmail.com>
+   (C) 2008 by The GRASS development team
 
+   \author Martin Landa <landa.martin gmail.com>
+
    \date 2008 
 */
 
+extern "C" {
+#include <grass/vedit.h>
+}
 #include "driver.h"
 #include "digit.h"
 
 /**
-   \brief Delete selected lines
+   \brief Add new vector feature
 
-   \return number of deleted lines
-   \return -1 on error
-*/
-int Digit::DeleteSelectedLines()
-{
-    int nlines = 0;
-
-    if (!display->mapInfo) {
-	return -1;
-    }
-
-    for(std::vector<int>::iterator i = display->selected.begin(), e = display->selected.end();
-	i != e; ++i) {
-	Vect_delete_line(display->mapInfo, *i);
-    }
-
-    return nlines;
-}
-
-/**
-   \brief Add new line
-
-   For feature type see include/vect/dig_defines.h
-       #define GV_POINT      0x01
-       #define GV_LINE	     0x02
-       #define GV_BOUNDARY   0x04
-       #define GV_CENTROID   0x08
-
-       (unsupported)
-       #define GV_FACE       0x10
-1       #define GV_KERNEL     0x20
-       #define GV_AREA	     0x40
-       #define GV_VOLUME     0x80
-
    \param type   feature type
-   \param coords pairs of coordinates list
-   \param with_z 3D?
+   \param coords pairs of coordinates list (2D or 3D map)
+   \param layer  layer number
+   \param cat    category number
+   \param bgmap  map of background map or NULL
+   \param snap   snapping mode (see vedit.h)
+   \param thresh threshold value for snapping
 
    \return 1 on success
    \return -1 on failure
 */
-int Digit::AddLine(int type, std::vector<double> coords, bool with_z, int layer, int cat)
+int Digit::AddLine(int type, std::vector<double> coords, int layer, int cat,
+		   const char *bgmap, int snap, double threshold)
 {
     int i, npoints;
+    int newline;
 
     struct line_pnts *Points;
     struct line_cats *Cats;
 
+    struct Map_info **BgMap; /* backgroud vector maps */
+    int nbgmaps;             /* number of registrated background maps */
+
     if (!display->mapInfo) {
 	return -1;
     }
 
-    npoints = coords.size() / (with_z ? 3 : 2);
-    if (coords.size() != npoints * (with_z ? 3 : 2)) {
+    npoints = coords.size() / (Vect_is_3d(display->mapInfo) ? 3 : 2);
+    if (coords.size() != npoints * (Vect_is_3d(display->mapInfo) ? 3 : 2)) {
 	return -1;
     }
 
+    G_debug(1, "Digit.AddLine(): npoints=%d", npoints);
+
     /* TODO: 3D */
     if (!(type & GV_POINTS) && !(type & GV_LINES)) {
 	return -1;
@@ -85,6 +66,23 @@
 	return -1;
     }
 
+    BgMap = NULL;
+
+    if (bgmap) {
+	const char *mapset;
+	mapset = G_find_vector2 (bgmap, ""); 
+	if (mapset) {
+	    if (strcmp(G_fully_qualified_name((const char*) display->mapInfo->name, (const char*) G_mapset()),
+		       G_fully_qualified_name((const char*) bgmap, (const char*) mapset))) {
+		nbgmaps = 1;
+		BgMap = (struct Map_info**) G_realloc ((void *) BgMap, nbgmaps * sizeof(struct Map_info*));
+		BgMap[nbgmaps-1] = (struct Map_info *) G_malloc (sizeof(struct Map_info));
+		
+		Vect_open_old(BgMap[nbgmaps-1], (char *) bgmap, (char*) mapset);
+	    }
+	}
+    }
+
     Points = Vect_new_line_struct();
     Cats = Vect_new_cats_struct();
 
@@ -96,7 +94,7 @@
 
     i = 0;
     while (i < coords.size()) {
-	if (with_z) {
+	if (Vect_is_3d(display->mapInfo)) {
 	    Vect_append_point(Points, coords[i], coords[i+1], coords[i+2]);
 	    i += 3;
 	}
@@ -110,17 +108,358 @@
 	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],
-				 with_z) <= display->settings.threshold) {
+				 Vect_is_3d(display->mapInfo)) <= threshold) {
 	    Points->x[last] = Points->x[0];
 	    Points->y[last] = Points->y[0];
 	    Points->z[last] = Points->z[0];
+	    G_debug(3, "Digit.AddLine(): boundary closed");
 	}
     }
 
-    Vect_write_line(display->mapInfo, type, Points, Cats);
+    newline = Vect_write_line(display->mapInfo, type, Points, Cats);
 
+    if (snap != NO_SNAP) { /* apply snapping */
+	Vedit_snap_line(display->mapInfo, BgMap, nbgmaps, /* limited only to one background map */
+			newline,
+			threshold, (SNAP) ? 0 : 1); /* snap to vertex ? */
+    }
+
     Vect_destroy_line_struct(Points);
     Vect_destroy_cats_struct(Cats);
 
+    if (BgMap && BgMap[0]) {
+	Vect_close(BgMap[0]);
+    }
+
     return 1;
 }
+
+/**
+   \brief Rewrite given line
+
+   \param line line id
+   \param coords line geometry
+
+   \return new line id
+   \return -1 error
+*/
+int Digit::RewriteLine(int line, std::vector<double> coords)
+{
+    int ret, type, dim;
+    double x, y, z;
+    struct line_pnts *points;
+    struct line_cats *cats;
+
+    if (!display->mapInfo) {
+	return -1;
+    }
+
+    /* line alive ? */
+    if (!Vect_line_alive(display->mapInfo, line)) {
+	return -1;
+    }
+    
+    ret = 0;
+    points = Vect_new_line_struct();
+    cats = Vect_new_cats_struct();
+
+    /* read line */
+    type = Vect_read_line(display->mapInfo, NULL, cats, line);
+    if (type < 0) {
+	ret = -1;
+    }
+
+    /* define line geometry */
+    if (Vect_is_3d(display->mapInfo)) {
+	dim = 3;
+    }
+    else {
+	dim = 2;
+    }
+    for(size_t i = dim - 1; i < coords.size(); i += dim) {
+	if (dim == 2) {
+	    Vect_append_point(points, coords[i-1], coords[i], 0.0);
+	}
+	else {
+	    Vect_append_point(points, coords[i-2], coords[i-1], coords[i]);
+	}
+    }
+
+    /* rewrite line */
+    if (ret == 0) {
+	if (Vect_rewrite_line(display->mapInfo, line, type, points, cats) < 0) {
+	    ret = -1;
+	}
+    }
+
+    Vect_destroy_line_struct(points);
+    Vect_destroy_cats_struct(cats);
+
+    return ret;
+}
+
+/**
+   \brief Split/break selected line
+
+   Shape of line is not changed.
+
+   \param x,y,z coordinates (z is used only if map is 3d)
+   \param thresh threshold value to find a point on line
+*/
+int Digit::SplitLine(double x, double y, double z,
+		     double thresh)
+{
+    int ret;
+    struct line_pnts *point;
+
+    if (!display->mapInfo)
+	return -1;
+
+    point = Vect_new_line_struct();
+    Vect_append_point(point, x, y, z);
+
+    ret = Vedit_split_lines(display->mapInfo, display->selected,
+			    point, thresh, NULL);
+
+    Vect_destroy_line_struct(point);
+
+    return ret;
+}
+
+/**
+   \brief Delete selected vector features
+
+   \return number of deleted lines
+   \return -1 on error
+*/
+int Digit::DeleteLines()
+{
+    int ret;
+
+    if (!display->mapInfo) {
+	return -1;
+    }
+
+    ret = Vedit_delete_lines(display->mapInfo, display->selected);
+
+    return ret;
+}
+
+
+/** 
+    \brief Move selected vector features
+
+    \param move_x,move_y,move_z move direction (move_z is used only if map is 3D)
+    \param snap snapping move (see vedit.h)
+    \param thresh threshold value for snapping
+
+    \return number of moved features
+    \return -1 on error
+*/
+int Digit::MoveLines(double move_x, double move_y, double move_z,
+		     int snap, double thresh)
+{
+    int ret;
+
+    if (!display->mapInfo)
+	return -1;
+
+    ret = Vedit_move_lines(display->mapInfo, display->selected,
+			   move_x, move_y, move_z,
+			   snap, thresh);
+
+    return ret;
+}
+
+/**
+   \brief Flip selected lines/boundaries
+
+   \return number of modified lines
+   \return -1 on error
+*/
+int Digit::FlipLines()
+{
+    int ret;
+
+    if (!display->mapInfo) {
+	return -1;
+    }
+
+    /*
+      ret = Vedit_flip_lines(display->mapInfo, display->selected);
+    */
+
+    return ret;
+}
+
+/**
+   \brief Merge selected lines/boundaries
+
+   \return number of modified lines
+   \return -1 on error
+*/
+int Digit::MergeLines()
+{
+    int ret;
+
+    if (!display->mapInfo) {
+	return -1;
+    }
+
+    /*
+      ret = Vedit_merge_lines(display->mapInfo, display->selected);
+    */
+
+    return ret;
+}
+
+/**
+   \brief Breaks selected lines/boundaries
+
+   \return number of modified lines
+   \return -1 on error
+*/
+int Digit::BreakLines()
+{
+    int ret;
+
+    if (!display->mapInfo) {
+	return -1;
+    }
+
+    /*
+    ret = Vect_break_lines_list(display->mapInfo, display->selected,
+				GV_LINES, NULL, NULL);
+    */
+
+    return ret;
+}
+
+/**
+   \brief Snap selected lines/boundaries
+
+   \param thresh threshold value for snapping
+
+   \return number of modified lines
+   \return -1 on error
+*/
+int Digit::SnapLines(double thresh)
+{
+    int ret;
+
+    if (!display->mapInfo) {
+	return -1;
+    }
+
+    /*
+    Vect_snap_lines_list (display->mapInfo, display->selected,
+    thresh, NULL, NULL);
+    */
+    return ret;
+}
+
+/**
+   \brief Connect two selected lines/boundaries
+
+   \return 1 lines connected
+   \return 0 lines not connected
+   \return -1 on error
+*/
+int Digit::ConnectLines(double thresh)
+{
+    int ret;
+
+    if (!display->mapInfo) {
+	return -1;
+    }
+
+    /*
+    ret = Vedit_connect_lines(&Map, List,
+			      thresh);
+    */
+    return ret;
+}
+
+/**
+   \brief Automated labeling (z coordinate assignment) of vector lines (contours).
+
+   Modified vector map must be 3D.
+
+   \param x1,y1,x2,y2 line nodes for intersection
+   \param start starting value
+   \param step  step value for labeling
+
+   \return number of modified lines
+   \return -1 on error
+*/
+int Digit::ZBulkLabeling(double x1, double y1, double x2, double y2,
+			 double start, double step)
+{
+    int ret;
+
+    if (!display->mapInfo) {
+	return -1;
+    }
+
+    /*
+    ret = Vedit_bulk_labeling (display->mapInfo, display->selected,
+			       x1, y1, x2, y2, start, step);
+    */
+
+    return ret;
+}
+
+/**
+   \brief Copy vector features
+
+   \param ids line ids to be copied (if not given selected are used)
+   \param bgmap name of background map (if not given, copy features from input)
+
+   \return number of copied features
+   \return -1 on error
+*/
+int Digit::CopyLines(std::vector<int> ids, const char* bgmap_name)
+{
+    int ret;
+    struct Map_info *bgMap;
+    struct ilist *list;
+
+    bgMap = NULL;
+    list = NULL;
+
+    if (!display->mapInfo) {
+	return -1;
+    }
+
+
+    if (bgmap_name) {
+	const char *mapset;
+	bgMap = (struct Map_info *) G_malloc(sizeof (struct Map_info));
+	mapset = G_find_vector2 (bgmap_name, ""); 
+	Vect_open_old(bgMap, (char *) bgmap_name, (char *) mapset); /* TODO */
+    }
+
+/*
+    if (!ids.empty) {
+	list = Vect_new_list_struct();
+    }
+    else {
+	list = display->selected;
+    }
+
+    int Vedit_copy_lines (display->mapInfo, bgMap,
+			  list);
+
+    if (list != display->selected) {
+	Vect_destroy_list_struct(list);
+    }
+*/
+
+    if (bgMap) {
+	Vect_close(bgMap);
+	G_free ((void *) bgMap);
+    }
+
+    return ret;
+    
+}

Added: grass/trunk/gui/wxpython/vdigit/vertex.cpp
===================================================================
--- grass/trunk/gui/wxpython/vdigit/vertex.cpp	                        (rev 0)
+++ grass/trunk/gui/wxpython/vdigit/vertex.cpp	2008-01-14 22:16:45 UTC (rev 29710)
@@ -0,0 +1,97 @@
+/**
+   \file vertex.cpp
+
+   \brief Vertex manipulation
+
+   This program is free software under the GNU General Public
+   License (>=v2). Read the file COPYING that comes with GRASS
+   for details.
+
+   (C) 2008 by The GRASS development team
+
+   \author Martin Landa <landa.martin gmail.com>
+
+   \date 2008 
+*/
+
+extern "C" {
+#include <grass/vedit.h>
+}
+#include "driver.h"
+#include "digit.h"
+
+/**
+   \brief Move vertex
+
+   \param x,y,z coordinates (z is used only if map is 3d)
+   \param move_x,move_y,move_z direction for moving vertex
+   \param snap snap mode (see vector/v.edit/lib/vedit.h)
+   \param thresh threshold value to identify vertex position
+
+   \param 1 vertex added/removed
+   \param 0 nothing changed
+   \param -1 error
+*/
+int Digit::MoveVertex(double x, double y, double z,
+		      double move_x, double move_y, double move_z,
+		      int snap, double thresh) {
+
+    int ret;
+    struct line_pnts *point;
+
+    if (!display->mapInfo)
+	return -1;
+
+    point = Vect_new_line_struct();
+    Vect_append_point(point, x, y, z);
+
+    /* move only first found vertex in bbox */
+    ret = Vedit_move_vertex(display->mapInfo, NULL, 0, /* TODO: BG */
+			    display->selected,
+			    point, thresh,
+			    move_x, move_y, move_z,
+			    1, (snap == SNAPVERTEX) ? 1 : 0); 
+
+    Vect_destroy_line_struct(point);
+
+    return ret;
+}
+
+/**
+   \brief Add or remove vertex
+
+   Shape of line/boundary is not changed when adding new vertex.
+   
+   \param add add or remove vertex?
+   \param x,y,z coordinates (z is used only if map is 3d
+   \param thresh threshold value to identify vertex position
+
+   \param 1 vertex added/removed
+   \param 0 nothing changed
+   \param -1 error
+*/
+int Digit::ModifyLineVertex(int add, double x, double y, double z,
+			    double thresh)
+{
+    int ret;
+    struct line_pnts *point;
+
+    if (!display->mapInfo || display->selected->n_values != 1)
+	return -1;
+
+    point = Vect_new_line_struct();
+    Vect_append_point(point, x, y, z);
+
+    if (add) {
+	ret = Vedit_add_vertex(display->mapInfo, display->selected,
+			       point, thresh);
+    }
+    else {
+	ret = Vedit_remove_vertex(display->mapInfo, display->selected,
+				  point, thresh);
+    }
+
+    Vect_destroy_line_struct(point);
+
+    return ret;
+}



More information about the grass-commit mailing list