diff options
| author | Tavmjong Bah <tavmjong@free.fr> | 2016-11-16 15:22:39 +0000 |
|---|---|---|
| committer | tavmjong-free <tavmjong@free.fr> | 2016-11-16 15:22:39 +0000 |
| commit | 09d3ef953448a73c20dc1a70c2f96e0ac5019f45 (patch) | |
| tree | e5a4580d6dda384e4c8e3e04e7dd8a46a30d576d /src | |
| parent | Implement tweaking of mesh handle colors. (diff) | |
| download | inkscape-09d3ef953448a73c20dc1a70c2f96e0ac5019f45.tar.gz inkscape-09d3ef953448a73c20dc1a70c2f96e0ac5019f45.zip | |
Split selected rows/columns in half using Insert key.
(bzr r15251)
Diffstat (limited to 'src')
| -rw-r--r-- | src/sp-mesh-array.cpp | 63 | ||||
| -rw-r--r-- | src/sp-mesh-array.h | 4 | ||||
| -rw-r--r-- | src/ui/tools/mesh-tool.cpp | 16 |
3 files changed, 78 insertions, 5 deletions
diff --git a/src/sp-mesh-array.cpp b/src/sp-mesh-array.cpp index 565551fd4..2340b1936 100644 --- a/src/sp-mesh-array.cpp +++ b/src/sp-mesh-array.cpp @@ -38,6 +38,7 @@ */ #include <glibmm.h> +#include <set> // For color picking #include "display/drawing.h" @@ -2425,6 +2426,68 @@ guint SPMeshNodeArray::color_pick( std::vector<guint> icorners, SPItem* item ) { } /** + Splits selected rows and/or columns in half (according to the path 't' parameter). + Input is a list of selected corner draggable indices. +*/ +guint SPMeshNodeArray::insert( std::vector<guint> corners ) { + + guint inserted = 0; + + if( corners.size() < 2 ) return 0; + + std::set<guint> columns; + std::set<guint> rows; + + for( guint i = 0; i < corners.size()-1; ++i ) { + for( guint j = i+1; j < corners.size(); ++j ) { + + // This works as all corners have indices and they + // are numbered in order by row and column (and + // the node array is rectangular). + + guint c1 = corners[i]; + guint c2 = corners[j]; + if (c2 < c1) { + c1 = corners[j]; + c2 = corners[i]; + } + + // Number of corners in a row of patches. + guint ncorners = patch_columns() + 1; + + guint crow1 = c1 / ncorners; + guint crow2 = c2 / ncorners; + guint ccol1 = c1 % ncorners; + guint ccol2 = c2 % ncorners; + + // Check for horizontal neighbors + if ( crow1 == crow2 && (ccol2 - ccol1) == 1 ) { + columns.insert( ccol1 ); + } + + // Check for vertical neighbors + if ( ccol1 == ccol2 && (crow2 - crow1) == 1 ) { + rows.insert( crow1 ); + } + } + } + + // Iterate backwards so column/row numbers are not invalidated. + std::set<guint>::reverse_iterator rit; + for (rit=columns.rbegin(); rit != columns.rend(); ++rit) { + split_column( *rit, 0.5); + ++inserted; + } + for (rit=rows.rbegin(); rit != rows.rend(); ++rit) { + split_row( *rit, 0.5); + ++inserted; + } + + if( inserted > 0 ) built = false; + return inserted; +} + +/** Moves handles in response to a corner node move. p_old: orignal position of moved corner node. corner: the corner node moved (draggable index, i.e. point_i). diff --git a/src/sp-mesh-array.h b/src/sp-mesh-array.h index ee9243753..df43638db 100644 --- a/src/sp-mesh-array.h +++ b/src/sp-mesh-array.h @@ -76,7 +76,8 @@ enum MeshCornerOperation { MG_CORNER_SIDE_ARC, MG_CORNER_TENSOR_TOGGLE, MG_CORNER_COLOR_SMOOTH, - MG_CORNER_COLOR_PICK + MG_CORNER_COLOR_PICK, + MG_CORNER_INSERT }; enum MeshNodeOperation { @@ -192,6 +193,7 @@ public: unsigned int tensor_toggle( std::vector< unsigned int > ); unsigned int color_smooth( std::vector< unsigned int > ); unsigned int color_pick( std::vector< unsigned int >, SPItem* ); + unsigned int insert( std::vector< unsigned int > ); // Update other nodes in response to a node move. void update_handles( unsigned int corner, std::vector< unsigned int > selected_corners, Geom::Point old_p, MeshNodeOperation op ); diff --git a/src/ui/tools/mesh-tool.cpp b/src/ui/tools/mesh-tool.cpp index 61793b8b3..1f6e6ed87 100644 --- a/src/ui/tools/mesh-tool.cpp +++ b/src/ui/tools/mesh-tool.cpp @@ -389,6 +389,11 @@ sp_mesh_context_corner_operation (MeshTool *rc, MeshCornerOperation operation ) noperation += mg->array.color_pick( iter->second, items[iter->first] ); break; + case MG_CORNER_INSERT: + // std::cout << "INSERT" << std::endl; + noperation += mg->array.insert( iter->second ); + break; + default: std::cout << "sp_mesh_corner_operation: unknown operation" << std::endl; } @@ -420,6 +425,10 @@ sp_mesh_context_corner_operation (MeshTool *rc, MeshCornerOperation operation ) DocumentUndo::done(doc, SP_VERB_CONTEXT_MESH, _("Picked mesh corner color.")); break; + case MG_CORNER_INSERT: + DocumentUndo::done(doc, SP_VERB_CONTEXT_MESH, _("Inserted new row or column.")); + break; + default: std::cout << "sp_mesh_corner_operation: unknown operation" << std::endl; } @@ -896,11 +905,12 @@ bool MeshTool::root_handler(GdkEvent* event) { } break; + // Mesh Operations -------------------------------------------- + case GDK_KEY_Insert: case GDK_KEY_KP_Insert: // with any modifiers: - //sp_gradient_context_add_stops_between_selected_stops (rc); - std::cout << "Inserting stops between selected stops not implemented yet" << std::endl; + sp_mesh_context_corner_operation ( this, MG_CORNER_INSERT ); ret = TRUE; break; @@ -913,8 +923,6 @@ bool MeshTool::root_handler(GdkEvent* event) { } break; - // Mesh Operations -------------------------------------------- - case GDK_KEY_b: // Toggle mesh side between lineto and curveto. case GDK_KEY_B: if (MOD__ALT(event) && drag->isNonEmpty() && drag->hasSelection()) { |
