acc10389c1bb8c05e02553fbe8de1abd7864a780
1 /** \file
2 * Pencil event context implementation.
3 */
5 /*
6 * Authors:
7 * Lauris Kaplinski <lauris@kaplinski.com>
8 * bulia byak <buliabyak@users.sf.net>
9 *
10 * Copyright (C) 2000 Lauris Kaplinski
11 * Copyright (C) 2000-2001 Ximian, Inc.
12 * Copyright (C) 2002 Lauris Kaplinski
13 * Copyright (C) 2004 Monash University
14 *
15 * Released under GNU GPL, read the file 'COPYING' for more information
16 */
18 #include <gdk/gdkkeysyms.h>
20 #include "pencil-context.h"
21 #include "desktop.h"
22 #include "desktop-handles.h"
23 #include "selection.h"
24 #include "selection-chemistry.h"
25 #include "draw-anchor.h"
26 #include "message-stack.h"
27 #include "message-context.h"
28 #include "modifier-fns.h"
29 #include "sp-path.h"
30 #include "preferences.h"
31 #include "snap.h"
32 #include "pixmaps/cursor-pencil.xpm"
33 #include "display/bezier-utils.h"
34 #include "display/canvas-bpath.h"
35 #include <glibmm/i18n.h>
36 #include "libnr/in-svg-plane.h"
37 #include "context-fns.h"
38 #include "sp-namedview.h"
39 #include "xml/repr.h"
40 #include "document.h"
41 #include "desktop-style.h"
42 #include "macros.h"
43 #include "display/curve.h"
45 static void sp_pencil_context_class_init(SPPencilContextClass *klass);
46 static void sp_pencil_context_init(SPPencilContext *pc);
47 static void sp_pencil_context_setup(SPEventContext *ec);
48 static void sp_pencil_context_dispose(GObject *object);
50 static gint sp_pencil_context_root_handler(SPEventContext *event_context, GdkEvent *event);
51 static gint pencil_handle_button_press(SPPencilContext *const pc, GdkEventButton const &bevent);
52 static gint pencil_handle_motion_notify(SPPencilContext *const pc, GdkEventMotion const &mevent);
53 static gint pencil_handle_button_release(SPPencilContext *const pc, GdkEventButton const &revent);
54 static gint pencil_handle_key_press(SPPencilContext *const pc, guint const keyval, guint const state);
56 static void spdc_set_startpoint(SPPencilContext *pc, Geom::Point const p);
57 static void spdc_set_endpoint(SPPencilContext *pc, Geom::Point const p);
58 static void spdc_finish_endpoint(SPPencilContext *pc);
59 static void spdc_add_freehand_point(SPPencilContext *pc, Geom::Point p, guint state);
60 static void fit_and_split(SPPencilContext *pc);
63 static SPDrawContextClass *pencil_parent_class;
64 static Geom::Point pencil_drag_origin_w(0, 0);
65 static bool pencil_within_tolerance = false;
67 /**
68 * Register SPPencilContext class with Gdk and return its type number.
69 */
70 GType
71 sp_pencil_context_get_type()
72 {
73 static GType type = 0;
74 if (!type) {
75 GTypeInfo info = {
76 sizeof(SPPencilContextClass),
77 NULL, NULL,
78 (GClassInitFunc) sp_pencil_context_class_init,
79 NULL, NULL,
80 sizeof(SPPencilContext),
81 4,
82 (GInstanceInitFunc) sp_pencil_context_init,
83 NULL, /* value_table */
84 };
85 type = g_type_register_static(SP_TYPE_DRAW_CONTEXT, "SPPencilContext", &info, (GTypeFlags)0);
86 }
87 return type;
88 }
90 /**
91 * Initialize SPPencilContext vtable.
92 */
93 static void
94 sp_pencil_context_class_init(SPPencilContextClass *klass)
95 {
96 GObjectClass *object_class;
97 SPEventContextClass *event_context_class;
99 object_class = (GObjectClass *) klass;
100 event_context_class = (SPEventContextClass *) klass;
102 pencil_parent_class = (SPDrawContextClass*)g_type_class_peek_parent(klass);
104 object_class->dispose = sp_pencil_context_dispose;
106 event_context_class->setup = sp_pencil_context_setup;
107 event_context_class->root_handler = sp_pencil_context_root_handler;
108 }
110 /**
111 * Callback to initialize SPPencilContext object.
112 */
113 static void
114 sp_pencil_context_init(SPPencilContext *pc)
115 {
116 SPEventContext *event_context = SP_EVENT_CONTEXT(pc);
118 event_context->cursor_shape = cursor_pencil_xpm;
119 event_context->hot_x = 4;
120 event_context->hot_y = 4;
122 pc->npoints = 0;
123 pc->state = SP_PENCIL_CONTEXT_IDLE;
124 pc->req_tangent = Geom::Point(0, 0);
125 }
127 /**
128 * Callback to setup SPPencilContext object.
129 */
130 static void
131 sp_pencil_context_setup(SPEventContext *ec)
132 {
133 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
134 if (prefs->getBool("/tools/freehand/pencil/selcue")) {
135 ec->enableSelectionCue();
136 }
138 if (((SPEventContextClass *) pencil_parent_class)->setup) {
139 ((SPEventContextClass *) pencil_parent_class)->setup(ec);
140 }
142 SPPencilContext *const pc = SP_PENCIL_CONTEXT(ec);
143 pc->is_drawing = false;
145 pc->anchor_statusbar = false;
146 }
148 static void
149 sp_pencil_context_dispose(GObject *object)
150 {
151 G_OBJECT_CLASS(pencil_parent_class)->dispose(object);
152 }
154 /** Snaps new node relative to the previous node. */
155 static void
156 spdc_endpoint_snap(SPPencilContext const *pc, Geom::Point &p, guint const state)
157 {
158 if ((state & GDK_CONTROL_MASK)) { //CTRL enables constrained snapping
159 spdc_endpoint_snap_rotation(pc, p, pc->p[0], state);
160 } else {
161 if (!(state & GDK_SHIFT_MASK)) { //SHIFT disables all snapping, except the angular snapping above
162 //After all, the user explicitely asked for angular snapping by
163 //pressing CTRL
164 spdc_endpoint_snap_free(pc, p, state);
165 }
166 }
167 }
169 /**
170 * Callback for handling all pencil context events.
171 */
172 gint
173 sp_pencil_context_root_handler(SPEventContext *const ec, GdkEvent *event)
174 {
175 SPPencilContext *const pc = SP_PENCIL_CONTEXT(ec);
177 gint ret = FALSE;
179 switch (event->type) {
180 case GDK_BUTTON_PRESS:
181 ret = pencil_handle_button_press(pc, event->button);
182 break;
184 case GDK_MOTION_NOTIFY:
185 ret = pencil_handle_motion_notify(pc, event->motion);
186 break;
188 case GDK_BUTTON_RELEASE:
189 ret = pencil_handle_button_release(pc, event->button);
190 break;
192 case GDK_KEY_PRESS:
193 ret = pencil_handle_key_press(pc, get_group0_keyval (&event->key), event->key.state);
194 break;
196 default:
197 break;
198 }
200 if (!ret) {
201 gint (*const parent_root_handler)(SPEventContext *, GdkEvent *)
202 = ((SPEventContextClass *) pencil_parent_class)->root_handler;
203 if (parent_root_handler) {
204 ret = parent_root_handler(ec, event);
205 }
206 }
208 return ret;
209 }
211 static gint
212 pencil_handle_button_press(SPPencilContext *const pc, GdkEventButton const &bevent)
213 {
214 gint ret = FALSE;
215 SPEventContext *event_context = SP_EVENT_CONTEXT(pc);
216 if ( bevent.button == 1 && !event_context->space_panning) {
218 SPDrawContext *dc = SP_DRAW_CONTEXT (pc);
219 SPDesktop *desktop = SP_EVENT_CONTEXT_DESKTOP(dc);
220 Inkscape::Selection *selection = sp_desktop_selection(desktop);
222 if (Inkscape::have_viable_layer(desktop, dc->_message_context) == false) {
223 return TRUE;
224 }
226 Geom::Point const button_w(bevent.x, bevent.y);
228 /* Find desktop coordinates */
229 Geom::Point p = pc->desktop->w2d(button_w);
231 /* Test whether we hit any anchor. */
232 SPDrawAnchor *anchor = spdc_test_inside(pc, button_w);
234 pencil_drag_origin_w = Geom::Point(bevent.x,bevent.y);
235 pencil_within_tolerance = true;
237 switch (pc->state) {
238 case SP_PENCIL_CONTEXT_ADDLINE:
239 /* Current segment will be finished with release */
240 ret = TRUE;
241 break;
242 default:
243 /* Set first point of sequence */
244 if (bevent.state & GDK_CONTROL_MASK) {
245 spdc_create_single_dot(event_context, from_2geom(p), "/tools/freehand/pencil", bevent.state);
246 ret = true;
247 break;
248 }
249 if (anchor) {
250 p = to_2geom(anchor->dp);
251 desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Continuing selected path"));
252 } else {
254 if (!(bevent.state & GDK_SHIFT_MASK)) {
256 // This is the first click of a new curve; deselect item so that
257 // this curve is not combined with it (unless it is drawn from its
258 // anchor, which is handled by the sibling branch above)
259 selection->clear();
260 desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Creating new path"));
261 SnapManager &m = desktop->namedview->snap_manager;
262 m.setup(desktop);
263 Inkscape::SnappedPoint const s = m.freeSnap(Inkscape::SnapPreferences::SNAPPOINT_NODE, p);
264 if (s.getSnapped()) {
265 s.getPoint(p);
266 pc->pencil_has_snapped_before = true;
267 } else {
268 pc->pencil_has_snapped_before = false;
269 }
270 } else if (selection->singleItem() && SP_IS_PATH(selection->singleItem())) {
271 desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Appending to selected path"));
272 }
273 }
274 pc->sa = anchor;
275 spdc_set_startpoint(pc, from_2geom(p));
276 ret = TRUE;
277 break;
278 }
280 pc->is_drawing = true;
281 }
282 return ret;
283 }
285 static gint
286 pencil_handle_motion_notify(SPPencilContext *const pc, GdkEventMotion const &mevent)
287 {
288 if ((mevent.state & GDK_CONTROL_MASK) && (mevent.state & GDK_BUTTON1_MASK)) {
289 // mouse was accidentally moved during Ctrl+click;
290 // ignore the motion and create a single point
291 pc->is_drawing = false;
292 return TRUE;
293 }
294 gint ret = FALSE;
295 SPDesktop *const dt = pc->desktop;
297 SPEventContext *event_context = SP_EVENT_CONTEXT(pc);
298 if (event_context->space_panning || mevent.state & GDK_BUTTON2_MASK || mevent.state & GDK_BUTTON3_MASK) {
299 // allow scrolling
300 return FALSE;
301 }
303 if ( ( mevent.state & GDK_BUTTON1_MASK ) && !pc->grab && pc->is_drawing) {
304 /* Grab mouse, so release will not pass unnoticed */
305 pc->grab = SP_CANVAS_ITEM(dt->acetate);
306 sp_canvas_item_grab(pc->grab, ( GDK_KEY_PRESS_MASK | GDK_BUTTON_PRESS_MASK |
307 GDK_BUTTON_RELEASE_MASK |
308 GDK_POINTER_MOTION_MASK ),
309 NULL, mevent.time);
310 }
312 /* Find desktop coordinates */
313 Geom::Point p = to_2geom(dt->w2d(Geom::Point(mevent.x, mevent.y)));
315 /* Test whether we hit any anchor. */
316 SPDrawAnchor *anchor = spdc_test_inside(pc, Geom::Point(mevent.x, mevent.y));
318 if (pencil_within_tolerance) {
319 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
320 gint const tolerance = prefs->getIntLimited("/options/dragtolerance/value", 0, 0, 100);
321 if ( NR::LInfty( Geom::Point(mevent.x,mevent.y) - pencil_drag_origin_w ) < tolerance ) {
322 return FALSE; // Do not drag if we're within tolerance from origin.
323 }
324 }
326 // Once the user has moved farther than tolerance from the original location
327 // (indicating they intend to move the object, not click), then always process the
328 // motion notify coordinates as given (no snapping back to origin)
329 pencil_within_tolerance = false;
331 switch (pc->state) {
332 case SP_PENCIL_CONTEXT_ADDLINE:
333 /* Set red endpoint */
334 if (anchor) {
335 p = to_2geom(anchor->dp);
336 } else {
337 Geom::Point ptnr = from_2geom(p);
338 spdc_endpoint_snap(pc, ptnr, mevent.state);
339 p = to_2geom(ptnr);
340 }
341 spdc_set_endpoint(pc, from_2geom(p));
342 ret = TRUE;
343 break;
344 default:
345 /* We may be idle or already freehand */
346 if ( mevent.state & GDK_BUTTON1_MASK && pc->is_drawing ) {
347 pc->state = SP_PENCIL_CONTEXT_FREEHAND;
348 if ( !pc->sa && !pc->green_anchor ) {
349 /* Create green anchor */
350 pc->green_anchor = sp_draw_anchor_new(pc, pc->green_curve, TRUE, pc->p[0]);
351 }
352 /** \todo
353 * fixme: I am not sure whether we want to snap to anchors
354 * in middle of freehand (Lauris)
355 */
356 SnapManager &m = dt->namedview->snap_manager;
358 if (anchor) {
359 p = to_2geom(anchor->dp);
360 } else if ((mevent.state & GDK_SHIFT_MASK) == 0) {
361 m.setup(dt);
362 Inkscape::SnappedPoint const s = m.freeSnap(Inkscape::SnapPreferences::SNAPPOINT_NODE, p);
363 if (s.getSnapped()) {
364 s.getPoint(p);
365 pc->pencil_has_snapped_before = true;
366 }
367 }
368 if ( pc->npoints != 0) { // buttonpress may have happened before we entered draw context!
369 if (!(pc->pencil_has_snapped_before && m.snapprefs.getSnapPostponedGlobally())) {
370 // When snapping is enabled but temporarily on hold because the mouse is moving
371 // fast, then we don't want to add nodes off-grid
372 spdc_add_freehand_point(pc, from_2geom(p), mevent.state);
373 ret = TRUE;
374 }
375 }
377 if (anchor && !pc->anchor_statusbar) {
378 pc->_message_context->set(Inkscape::NORMAL_MESSAGE, _("<b>Release</b> here to close and finish the path."));
379 pc->anchor_statusbar = true;
380 } else if (!anchor && pc->anchor_statusbar) {
381 pc->_message_context->clear();
382 pc->anchor_statusbar = false;
383 } else if (!anchor) {
384 pc->_message_context->set(Inkscape::NORMAL_MESSAGE, _("Drawing a freehand path"));
385 }
387 } else {
388 if (anchor && !pc->anchor_statusbar) {
389 pc->_message_context->set(Inkscape::NORMAL_MESSAGE, _("<b>Drag</b> to continue the path from this point."));
390 pc->anchor_statusbar = true;
391 } else if (!anchor && pc->anchor_statusbar) {
392 pc->_message_context->clear();
393 pc->anchor_statusbar = false;
394 }
395 }
396 break;
397 }
398 return ret;
399 }
401 static gint
402 pencil_handle_button_release(SPPencilContext *const pc, GdkEventButton const &revent)
403 {
404 gint ret = FALSE;
406 SPEventContext *event_context = SP_EVENT_CONTEXT(pc);
407 if ( revent.button == 1 && pc->is_drawing && !event_context->space_panning) {
408 SPDesktop *const dt = pc->desktop;
410 pc->is_drawing = false;
412 /* Find desktop coordinates */
413 Geom::Point p = dt->w2d(Geom::Point(revent.x, revent.y));
415 /* Test whether we hit any anchor. */
416 SPDrawAnchor *anchor = spdc_test_inside(pc, Geom::Point(revent.x,
417 revent.y));
419 switch (pc->state) {
420 case SP_PENCIL_CONTEXT_IDLE:
421 /* Releasing button in idle mode means single click */
422 /* We have already set up start point/anchor in button_press */
423 if (!(revent.state & GDK_CONTROL_MASK)) {
424 // Ctrl+click creates a single point so only set context in ADDLINE mode when Ctrl isn't pressed
425 pc->state = SP_PENCIL_CONTEXT_ADDLINE;
426 }
427 ret = TRUE;
428 break;
429 case SP_PENCIL_CONTEXT_ADDLINE:
430 /* Finish segment now */
431 if (anchor) {
432 p = anchor->dp;
433 } else {
434 spdc_endpoint_snap(pc, p, revent.state);
435 }
436 pc->ea = anchor;
437 spdc_set_endpoint(pc, p);
438 spdc_finish_endpoint(pc);
439 pc->state = SP_PENCIL_CONTEXT_IDLE;
440 ret = TRUE;
441 break;
442 case SP_PENCIL_CONTEXT_FREEHAND:
443 /* Finish segment now */
444 /// \todo fixme: Clean up what follows (Lauris)
445 if (anchor) {
446 p = anchor->dp;
447 }
448 pc->ea = anchor;
449 /* Write curves to object */
451 dt->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Finishing freehand"));
453 spdc_concat_colors_and_flush(pc, FALSE);
454 pc->sa = NULL;
455 pc->ea = NULL;
456 if (pc->green_anchor) {
457 pc->green_anchor = sp_draw_anchor_destroy(pc->green_anchor);
458 }
459 pc->state = SP_PENCIL_CONTEXT_IDLE;
460 ret = TRUE;
461 break;
462 default:
463 break;
464 }
466 if (pc->grab) {
467 /* Release grab now */
468 sp_canvas_item_ungrab(pc->grab, revent.time);
469 pc->grab = NULL;
470 }
472 ret = TRUE;
473 }
474 return ret;
475 }
477 static void
478 pencil_cancel (SPPencilContext *const pc)
479 {
480 if (pc->grab) {
481 /* Release grab now */
482 sp_canvas_item_ungrab(pc->grab, 0);
483 pc->grab = NULL;
484 }
486 pc->is_drawing = false;
488 pc->state = SP_PENCIL_CONTEXT_IDLE;
490 pc->red_curve->reset();
491 sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(pc->red_bpath), NULL);
492 while (pc->green_bpaths) {
493 gtk_object_destroy(GTK_OBJECT(pc->green_bpaths->data));
494 pc->green_bpaths = g_slist_remove(pc->green_bpaths, pc->green_bpaths->data);
495 }
496 pc->green_curve->reset();
497 if (pc->green_anchor) {
498 pc->green_anchor = sp_draw_anchor_destroy(pc->green_anchor);
499 }
501 pc->_message_context->clear();
502 pc->_message_context->flash(Inkscape::NORMAL_MESSAGE, _("Drawing cancelled"));
504 sp_canvas_end_forced_full_redraws(pc->desktop->canvas);
505 }
507 static gint
508 pencil_handle_key_press(SPPencilContext *const pc, guint const keyval, guint const state)
509 {
510 gint ret = FALSE;
511 switch (keyval) {
512 case GDK_Up:
513 case GDK_Down:
514 case GDK_KP_Up:
515 case GDK_KP_Down:
516 // Prevent the zoom field from activation.
517 if (!mod_ctrl_only(state)) {
518 ret = TRUE;
519 }
520 break;
521 case GDK_Escape:
522 if (pc->npoints != 0) {
523 // if drawing, cancel, otherwise pass it up for deselecting
524 if (pc->state != SP_PENCIL_CONTEXT_IDLE) {
525 pencil_cancel (pc);
526 ret = TRUE;
527 }
528 }
529 break;
530 case GDK_z:
531 case GDK_Z:
532 if (mod_ctrl_only(state) && pc->npoints != 0) {
533 // if drawing, cancel, otherwise pass it up for undo
534 if (pc->state != SP_PENCIL_CONTEXT_IDLE) {
535 pencil_cancel (pc);
536 ret = TRUE;
537 }
538 }
539 break;
540 case GDK_g:
541 case GDK_G:
542 if (mod_shift_only(state)) {
543 sp_selection_to_guides(SP_EVENT_CONTEXT(pc)->desktop);
544 ret = true;
545 }
546 break;
547 default:
548 break;
549 }
550 return ret;
551 }
553 /**
554 * Reset points and set new starting point.
555 */
556 static void
557 spdc_set_startpoint(SPPencilContext *const pc, Geom::Point const p)
558 {
559 pc->npoints = 0;
560 pc->red_curve_is_valid = false;
561 if (in_svg_plane(p)) {
562 pc->p[pc->npoints++] = p;
563 }
564 }
566 /**
567 * Change moving endpoint position.
568 * <ul>
569 * <li>Ctrl constrains to moving to H/V direction, snapping in given direction.
570 * <li>Otherwise we snap freely to whatever attractors are available.
571 * </ul>
572 *
573 * Number of points is (re)set to 2 always, 2nd point is modified.
574 * We change RED curve.
575 */
576 static void
577 spdc_set_endpoint(SPPencilContext *const pc, Geom::Point const p)
578 {
579 if (pc->npoints == 0) {
580 return;
581 /* May occur if first point wasn't in SVG plane (e.g. weird w2d transform, perhaps from bad
582 * zoom setting).
583 */
584 }
585 g_return_if_fail( pc->npoints > 0 );
587 pc->red_curve->reset();
588 if ( ( p == pc->p[0] )
589 || !in_svg_plane(p) )
590 {
591 pc->npoints = 1;
592 } else {
593 pc->p[1] = p;
594 pc->npoints = 2;
596 pc->red_curve->moveto(pc->p[0]);
597 pc->red_curve->lineto(pc->p[1]);
598 pc->red_curve_is_valid = true;
600 sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(pc->red_bpath), pc->red_curve);
601 }
602 }
604 /**
605 * Finalize addline.
606 *
607 * \todo
608 * fixme: I'd like remove red reset from concat colors (lauris).
609 * Still not sure, how it will make most sense.
610 */
611 static void
612 spdc_finish_endpoint(SPPencilContext *const pc)
613 {
614 if ( ( pc->red_curve->is_empty() )
615 || ( *(pc->red_curve->first_point()) == *(pc->red_curve->second_point()) ) )
616 {
617 pc->red_curve->reset();
618 sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(pc->red_bpath), NULL);
619 } else {
620 /* Write curves to object. */
621 spdc_concat_colors_and_flush(pc, FALSE);
622 pc->sa = NULL;
623 pc->ea = NULL;
624 }
625 }
627 static void
628 spdc_add_freehand_point(SPPencilContext *pc, Geom::Point p, guint /*state*/)
629 {
630 g_assert( pc->npoints > 0 );
631 g_return_if_fail(unsigned(pc->npoints) < G_N_ELEMENTS(pc->p));
633 if ( ( p != pc->p[ pc->npoints - 1 ] )
634 && in_svg_plane(p) )
635 {
636 pc->p[pc->npoints++] = p;
637 fit_and_split(pc);
638 }
639 }
641 static inline double
642 square(double const x)
643 {
644 return x * x;
645 }
647 static void
648 fit_and_split(SPPencilContext *pc)
649 {
650 g_assert( pc->npoints > 1 );
652 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
653 double const tol = prefs->getDoubleLimited("/tools/freehand/pencil/tolerance", 10.0, 1.0, 100.0);
654 double const tolerance_sq = 0.02 * square( pc->desktop->w2d().descrim() * tol)
655 * exp(0.2*tol - 2);
657 Geom::Point b[4];
658 g_assert(is_zero(pc->req_tangent)
659 || is_unit_vector(pc->req_tangent));
660 Geom::Point const tHatEnd(0, 0);
661 int const n_segs = sp_bezier_fit_cubic_full(b, NULL, pc->p, pc->npoints,
662 pc->req_tangent, tHatEnd, tolerance_sq, 1);
663 if ( n_segs > 0
664 && unsigned(pc->npoints) < G_N_ELEMENTS(pc->p) )
665 {
666 /* Fit and draw and reset state */
667 pc->red_curve->reset();
668 pc->red_curve->moveto(b[0]);
669 pc->red_curve->curveto(b[1], b[2], b[3]);
670 sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(pc->red_bpath), pc->red_curve);
671 pc->red_curve_is_valid = true;
672 } else {
673 /* Fit and draw and copy last point */
675 g_assert(!pc->red_curve->is_empty());
677 /* Set up direction of next curve. */
678 {
679 Geom::CubicBezier const * last_seg = dynamic_cast<Geom::CubicBezier const *>(pc->red_curve->last_segment());
680 g_assert( last_seg ); // Relevance: validity of (*last_seg)[2]
681 pc->p[0] = last_seg->finalPoint();
682 pc->npoints = 1;
683 Geom::Point const req_vec( pc->p[0] - (*last_seg)[2] );
684 pc->req_tangent = ( ( Geom::is_zero(req_vec) || !in_svg_plane(req_vec) )
685 ? Geom::Point(0, 0)
686 : Geom::unit_vector(req_vec) );
687 }
689 pc->green_curve->append_continuous(pc->red_curve, 0.0625);
690 SPCurve *curve = pc->red_curve->copy();
692 /// \todo fixme:
693 SPCanvasItem *cshape = sp_canvas_bpath_new(sp_desktop_sketch(pc->desktop), curve);
694 curve->unref();
695 sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(cshape), pc->green_color, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT);
697 pc->green_bpaths = g_slist_prepend(pc->green_bpaths, cshape);
699 pc->red_curve_is_valid = false;
700 }
701 }
704 /*
705 Local Variables:
706 mode:c++
707 c-file-style:"stroustrup"
708 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
709 indent-tabs-mode:nil
710 fill-column:99
711 End:
712 */
713 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :