浏览代码

vlib: Vect_restore_line() added (initial step towards vector digitizer undo) - update https://trac.osgeo.org/grass/changeset/33533
(merge from devbr6, https://trac.osgeo.org/grass/changeset/35535)


git-svn-id: https://svn.osgeo.org/grass/grass/trunk@33536 15284696-431f-4ddb-bdfa-cd5b030d7da7

Martin Landa 16 年之前
父节点
当前提交
181163776d
共有 1 个文件被更改,包括 65 次插入30 次删除
  1. 65 30
      lib/vector/diglib/plus_line.c

+ 65 - 30
lib/vector/diglib/plus_line.c

@@ -17,34 +17,13 @@
 #include <stdlib.h>
 #include <grass/Vect.h>
 
-/*!
- * \brief Add new line to Plus_head structure.
- *
- * \param[in,out] plus pointer to Plus_head structure
- * \param[in] type feature type
- * \param[in] Points line geometry
- * \param[in] offset line offset
- *
- * \return -1 on error      
- * \return line id
- */
-int
-dig_add_line(struct Plus_head *plus, int type, struct line_pnts *Points,
-	     long offset)
+static int add_line(struct Plus_head *plus, int lineid, int type, struct line_pnts *Points,
+		    long offset)
 {
-    int lineid, node, lp;
+    int node, lp;
     P_LINE *line;
     BOUND_BOX box;
 
-    /* First look if we have space in array of pointers to lines
-     *  and reallocate if necessary */
-    if (plus->n_lines >= plus->alloc_lines) {	/* array is full */
-	if (dig_alloc_lines(plus, 1000) == -1)
-	    return -1;
-    }
-
-    /* allocate line structure */
-    lineid = plus->n_lines + 1;
     plus->Line[lineid] = dig_alloc_line();
     line = plus->Line[lineid];
 
@@ -98,6 +77,45 @@ dig_add_line(struct Plus_head *plus, int type, struct line_pnts *Points,
     line->S = 0;
     line->E = 0;
     line->W = 0;
+
+    dig_line_box(Points, &box);
+    dig_line_set_box(plus, lineid, &box);
+    dig_spidx_add_line(plus, lineid, &box);
+    if (plus->do_uplist)
+	dig_line_add_updated(plus, lineid);
+
+    return (lineid);
+}
+
+/*!
+ * \brief Add new line to Plus_head structure.
+ *
+ * \param[in,out] plus pointer to Plus_head structure
+ * \param[in] type feature type
+ * \param[in] Points line geometry
+ * \param[in] offset line offset
+ *
+ * \return -1 on error      
+ * \return line id
+ */
+int
+dig_add_line(struct Plus_head *plus, int type, struct line_pnts *Points,
+	     long offset)
+{
+    int ret;
+    
+    /* First look if we have space in array of pointers to lines
+     *  and reallocate if necessary */
+    if (plus->n_lines >= plus->alloc_lines) {	/* array is full */
+	if (dig_alloc_lines(plus, 1000) == -1)
+	    return -1;
+    }
+
+    ret = add_line(plus, plus->n_lines + 1, type, Points, offset);
+
+    if (ret == -1)
+	return ret;
+
     plus->n_lines++;
 
     switch (type) {
@@ -121,13 +139,30 @@ dig_add_line(struct Plus_head *plus, int type, struct line_pnts *Points,
 	break;
     }
 
-    dig_line_box(Points, &box);
-    dig_line_set_box(plus, lineid, &box);
-    dig_spidx_add_line(plus, lineid, &box);
-    if (plus->do_uplist)
-	dig_line_add_updated(plus, lineid);
+    return ret;
+}
 
-    return (lineid);
+/*!
+ * \brief Restore line in Plus_head structure.
+ *
+ * \param[in,out] plus pointer to Plus_head structure
+ * \param[in] type feature type
+ * \param[in] Points line geometry
+ * \param[in] offset line offset
+ *
+ * \return -1 on error      
+ * \return line id
+ */
+int
+dig_restore_line(struct Plus_head *plus, int lineid,
+		 int type, struct line_pnts *Points,
+		 long offset)
+{
+    if (lineid < 1 || lineid > plus->n_lines) {
+	return -1;
+    }
+
+    return add_line(plus, lineid, type, Points, offset);    
 }
 
 /*!