Merge lp:~inkscape.dev/inkscape/bendFromClipboard into lp:~inkscape.dev/inkscape/trunk

Proposed by Martin Owens
Status: Merged
Approved by: Jabiertxof
Approved revision: 12633
Merged at revision: 14269
Proposed branch: lp:~inkscape.dev/inkscape/bendFromClipboard
Merge into: lp:~inkscape.dev/inkscape/trunk
Diff against target: 172 lines (+75/-13)
2 files modified
src/ui/tools/freehand-base.cpp (+74/-13)
src/widgets/pencil-toolbar.cpp (+1/-0)
To merge this branch: bzr merge lp:~inkscape.dev/inkscape/bendFromClipboard
Reviewer Review Type Date Requested Status
njh style and general coding Approve
Review via email: mp+187934@code.launchpad.net

Description of the change

I made a new branch [1:bendFromClipboard] that make a bend liveeffect
with a full draw in clipboard using pen or pencil stroke. It use the
combo box in pen/pencil toolbox.

I have this on mind time ago but need to credit Vinícius for the videos
about his "Trace Pixel Art" feature, that refresh me.

The code is working, need review -im not a c++ developer- and has one
bug with selection. I explain:
When all is done i call to "selection->set(obj)". "obj" exist but this
code is ignored. I test it with second optional parameter to true and
the same.

Thanks in advance for test, reviews, help and feedback. Jabier.

To post a comment you must log in.
12597. By Jabiertxof <email address hidden>

update to trunk

12598. By Jabiertxof <email address hidden>

update to trunk

12599. By Jabiertxof <email address hidden>

update to trunk

12600. By Jabiertxof <email address hidden>

Update to trunk

12601. By Jabiertxof <email address hidden>

Fix errors on compile and in console detected by su_v, added selection of stroke used

12602. By Jabiertxof <email address hidden>

Update to trunk

12603. By Jabiertxof <email address hidden>

Fixing errors

12604. By Jabiertxof <email address hidden>

fixing bend warnings

12605. By Jabiertxof <email address hidden>

Update to trunk

12606. By Jabiertxof <email address hidden>

fixing bend warnings

12607. By Jabiertxof <email address hidden>

fixing bend warnings

12608. By Jabiertxof <email address hidden>

fixing last applied bend

12609. By Jabiertxof <email address hidden>

Make private bend parameter like original

12610. By Jabiertxof <email address hidden>

add empty line in bend parameter like original

12611. By Jabiertxof <email address hidden>

Removed BSpline from tell by su_v

12612. By Jabiertxof <email address hidden>

Update to trunk

12613. By Jabiertxof <email address hidden>

Update to trunk

12614. By Jabiertxof <email address hidden>

Update to trunk

12615. By Jabiertxof <email address hidden>

fix error su_v tell to me

12616. By Jabiertxof <email address hidden>

fix error su_v tell to me

12617. By Jabiertxof <email address hidden>

Fix repointed by su_v

12618. By Jabiertxof <email address hidden>

Update to trunk

12619. By Jabiertxof <email address hidden>

update to trunk

12620. By Jabiertxof <email address hidden>

update to trunk

12621. By root <email address hidden>

refactor from lastApplied

12622. By Jabiertxof <email address hidden>

fixing to trunk

12623. By Jabiertxof <email address hidden>

update to trunk

12624. By Jabiertxof <email address hidden>

Fixing bend from clipboard to trunk 0.92

12625. By Jabiertxof <email address hidden>

update to trunk

12626. By Jabiertxof <email address hidden>

updated code to work on 0.92 code

Revision history for this message
Jabiertxof (jabiertxof) wrote :
12627. By Jabiertxof <email address hidden>

update to trunk

12628. By Jabiertxof <email address hidden>

update to trunk

12629. By Jabiertxof <email address hidden>

Rename a variable to current coding style

12630. By Jabiertxof <email address hidden>

update to trunk

12631. By jabiertxof <email address hidden>

Fis fix a bug finded in my presentation in the HackFest

12632. By jabiertxof <email address hidden>

update to trunk

12633. By Jabiertxof <email address hidden>

update to trunk

Revision history for this message
njh (njh-njhurst) wrote :

I can't see anything wrong with this, approving.

review: Approve (style and general coding)
Revision history for this message
Jabiertxof (jabiertxof) wrote :

Thanks for the review Nathan!

12634. By Jabiertxof <email address hidden>

update to trunk

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/ui/tools/freehand-base.cpp'
2--- src/ui/tools/freehand-base.cpp 2015-07-27 10:21:31 +0000
3+++ src/ui/tools/freehand-base.cpp 2015-07-30 17:57:19 +0000
4@@ -20,6 +20,7 @@
5 # include "config.h"
6 #endif
7
8+#include "live_effects/lpe-bendpath.h"
9 #include "live_effects/lpe-patternalongpath.h"
10 #include "live_effects/lpe-simplify.h"
11 #include "display/canvas-bpath.h"
12@@ -267,6 +268,21 @@
13 lpe->getRepr()->setAttribute("offset_points", s.str().c_str());
14 }
15
16+static void spdc_apply_bend_shape(gchar const *svgd, FreehandBase *dc, SPItem *item)
17+{
18+ using namespace Inkscape::LivePathEffect;
19+ if(!SP_LPE_ITEM(item)->hasPathEffectOfType(BEND_PATH)){
20+ Effect::createAndApply(BEND_PATH, dc->desktop->doc(), item);
21+ }
22+ Effect* lpe = SP_LPE_ITEM(item)->getCurrentLPE();
23+
24+ // write bend parameters:
25+ lpe->getRepr()->setAttribute("bendpath", svgd);
26+ lpe->getRepr()->setAttribute("prop_scale", "1");
27+ lpe->getRepr()->setAttribute("scale_y_rel", "false");
28+ lpe->getRepr()->setAttribute("vertical", "false");
29+}
30+
31 static void spdc_apply_simplify(std::string threshold, FreehandBase *dc, SPItem *item)
32 {
33 using namespace Inkscape::LivePathEffect;
34@@ -282,6 +298,9 @@
35 lpe->getRepr()->setAttribute("simplifyJustCoalesce", "false");
36 }
37
38+enum shapeType { NONE, TRIANGLE_IN, TRIANGLE_OUT, ELLIPSE, CLIPBOARD, BEND_CLIPBOARD, LAST_APPLIED };
39+static shapeType previous_shape_type = NONE;
40+
41 static void spdc_check_for_and_apply_waiting_LPE(FreehandBase *dc, SPItem *item, SPCurve *curve)
42 {
43 using namespace Inkscape::LivePathEffect;
44@@ -305,22 +324,25 @@
45 }
46
47 //Store the clipboard path to apply in the future without the use of clipboard
48+
49 static Geom::PathVector previous_shape_pathv;
50- enum shapeType { NONE, TRIANGLE_IN, TRIANGLE_OUT, ELLIPSE, CLIPBOARD, LAST_APPLIED };
51- static shapeType previous_shape_type = NONE;
52+
53
54
55 shapeType shape = (shapeType)prefs->getInt(tool_name(dc) + "/shape", 0);
56 bool shape_applied = false;
57 SPCSSAttr *css_item = sp_css_attr_from_object(item, SP_STYLE_FLAG_ALWAYS);
58 const char *cstroke = sp_repr_css_property(css_item, "stroke", "none");
59+ static SPItem *bend_item;
60
61 #define SHAPE_LENGTH 10
62 #define SHAPE_HEIGHT 10
63
64+
65 if(shape == LAST_APPLIED){
66+
67 shape = previous_shape_type;
68- if(shape == CLIPBOARD){
69+ if(shape == CLIPBOARD || shape == BEND_CLIPBOARD){
70 shape = LAST_APPLIED;
71 }
72 }
73@@ -380,15 +402,52 @@
74 shape_applied = true;
75 break;
76 }
77+ case BEND_CLIPBOARD:
78+ {
79+ Inkscape::UI::ClipboardManager *cm = Inkscape::UI::ClipboardManager::get();
80+ if(cm->paste(SP_ACTIVE_DESKTOP,true) == true){
81+ gchar const *svgd = item->getRepr()->attribute("d");
82+ Geom::PathVector path = sp_svg_read_pathv(svgd);
83+ path *= item->i2doc_affine().inverse();
84+ svgd = sp_svg_write_path( path );
85+ bend_item = dc->selection->singleItem();
86+ bend_item->moveTo(item,false);
87+ spdc_apply_bend_shape(svgd, dc, bend_item);
88+ bend_item->transform = Geom::Affine(1,0,0,1,0,0);
89+ dc->selection->add(SP_OBJECT(bend_item));
90+ } else {
91+ shape = NONE;
92+ }
93+ break;
94+ }
95 case LAST_APPLIED:
96 {
97- if(previous_shape_pathv.size() != 0){
98- SPCurve * c = new SPCurve();
99- c->set_pathvector(previous_shape_pathv);
100- spdc_paste_curve_as_freehand_shape(c, dc, item);
101- c->unref();
102+ if(previous_shape_type == CLIPBOARD){
103+ if(previous_shape_pathv.size() != 0){
104+ SPCurve * c = new SPCurve();
105+ c->set_pathvector(previous_shape_pathv);
106+ spdc_paste_curve_as_freehand_shape(c, dc, item);
107+ c->unref();
108
109- shape_applied = true;
110+ shape_applied = true;
111+ }
112+ shape = CLIPBOARD;
113+ } else {
114+ if(bend_item != NULL && bend_item->getRepr() != NULL){
115+ gchar const *svgd = item->getRepr()->attribute("d");
116+ Geom::PathVector path = sp_svg_read_pathv(svgd);
117+ path *= item->i2doc_affine().inverse();
118+ svgd = sp_svg_write_path( path );
119+ dc->selection->add(SP_OBJECT(bend_item));
120+ sp_selection_duplicate(dc->desktop);
121+ dc->selection->remove(SP_OBJECT(bend_item));
122+ bend_item = dc->selection->singleItem();
123+ bend_item->moveTo(item,false);
124+ spdc_apply_bend_shape(svgd, dc, bend_item);
125+ bend_item->transform = Geom::Affine(1,0,0,1,0,0);
126+ dc->selection->add(SP_OBJECT(bend_item));
127+ }
128+ shape = BEND_CLIPBOARD;
129 }
130 break;
131 }
132@@ -667,7 +726,6 @@
133 static void spdc_flush_white(FreehandBase *dc, SPCurve *gc)
134 {
135 SPCurve *c;
136-
137 if (dc->white_curves) {
138 g_assert(dc->white_item);
139 c = SPCurve::concat(dc->white_curves);
140@@ -719,14 +777,17 @@
141 // Attach repr
142 SPItem *item = SP_ITEM(desktop->currentLayer()->appendChildRepr(repr));
143
144- // we finished the path; now apply any waiting LPEs or freehand shapes
145 spdc_check_for_and_apply_waiting_LPE(dc, item, c);
146-
147- dc->selection->set(repr);
148+ if(previous_shape_type != BEND_CLIPBOARD){
149+ dc->selection->set(repr);
150+ }
151 Inkscape::GC::release(repr);
152 item->transform = SP_ITEM(desktop->currentLayer())->i2doc_affine().inverse();
153 item->updateRepr();
154 item->doWriteTransform(item->getRepr(), item->transform, NULL, true);
155+ if(previous_shape_type == BEND_CLIPBOARD){
156+ repr->parent()->removeChild(repr);
157+ }
158 }
159
160 DocumentUndo::done(doc, SP_IS_PEN_CONTEXT(dc)? SP_VERB_CONTEXT_PEN : SP_VERB_CONTEXT_PENCIL,
161
162=== modified file 'src/widgets/pencil-toolbar.cpp'
163--- src/widgets/pencil-toolbar.cpp 2015-07-27 00:04:29 +0000
164+++ src/widgets/pencil-toolbar.cpp 2015-07-30 17:57:19 +0000
165@@ -178,6 +178,7 @@
166 glist = g_list_append (glist, _("Triangle out"));
167 glist = g_list_append (glist, _("Ellipse"));
168 glist = g_list_append (glist, _("From clipboard"));
169+ glist = g_list_append (glist, _("Bend from clipboard"));
170 glist = g_list_append (glist, _("Last applied"));
171
172 return glist;