Code

Spray Tool clean up and Toolbar refactoring
[inkscape.git] / src / box3d-context.cpp
1 #define __SP_BOX3D_CONTEXT_C__
3 /*
4  * 3D box drawing context
5  *
6  * Author:
7  *   Lauris Kaplinski <lauris@kaplinski.com>
8  *   bulia byak <buliabyak@users.sf.net>
9  *
10  * Copyright (C) 2007      Maximilian Albert <Anhalter42@gmx.de>
11  * Copyright (C) 2006      Johan Engelen <johan@shouraizou.nl>
12  * Copyright (C) 2000-2005 authors
13  * Copyright (C) 2000-2001 Ximian, Inc.
14  *
15  * Released under GNU GPL, read the file 'COPYING' for more information
16  */
18 #include "config.h"
20 #include <gdk/gdkkeysyms.h>
22 #include "macros.h"
23 #include "display/sp-canvas.h"
24 #include "document.h"
25 #include "sp-namedview.h"
26 #include "selection.h"
27 #include "selection-chemistry.h"
28 #include "desktop-handles.h"
29 #include "snap.h"
30 #include "display/curve.h"
31 #include "desktop.h"
32 #include "message-context.h"
33 #include "pixmaps/cursor-3dbox.xpm"
34 #include "box3d.h"
35 #include "box3d-context.h"
36 #include "sp-metrics.h"
37 #include <glibmm/i18n.h>
38 #include "object-edit.h"
39 #include "xml/repr.h"
40 #include "xml/node-event-vector.h"
41 #include "preferences.h"
42 #include "context-fns.h"
43 #include "desktop-style.h"
44 #include "transf_mat_3x4.h"
45 #include "perspective-line.h"
46 #include "persp3d.h"
47 #include "box3d-side.h"
48 #include "document-private.h"
49 #include "line-geometry.h"
50 #include "shape-editor.h"
52 static void sp_box3d_context_class_init(Box3DContextClass *klass);
53 static void sp_box3d_context_init(Box3DContext *box3d_context);
54 static void sp_box3d_context_dispose(GObject *object);
56 static void sp_box3d_context_setup(SPEventContext *ec);
57 static void sp_box3d_context_finish(SPEventContext *ec);
59 static gint sp_box3d_context_root_handler(SPEventContext *event_context, GdkEvent *event);
60 static gint sp_box3d_context_item_handler(SPEventContext *event_context, SPItem *item, GdkEvent *event);
62 static void sp_box3d_drag(Box3DContext &bc, guint state);
63 static void sp_box3d_finish(Box3DContext *bc);
65 static SPEventContextClass *parent_class;
67 GtkType sp_box3d_context_get_type()
68 {
69     static GType type = 0;
70     if (!type) {
71         GTypeInfo info = {
72             sizeof(Box3DContextClass),
73             NULL, NULL,
74             (GClassInitFunc) sp_box3d_context_class_init,
75             NULL, NULL,
76             sizeof(Box3DContext),
77             4,
78             (GInstanceInitFunc) sp_box3d_context_init,
79             NULL,    /* value_table */
80         };
81         type = g_type_register_static(SP_TYPE_EVENT_CONTEXT, "Box3DContext", &info, (GTypeFlags) 0);
82     }
83     return type;
84 }
86 static void sp_box3d_context_class_init(Box3DContextClass *klass)
87 {
88     GObjectClass *object_class = (GObjectClass *) klass;
89     SPEventContextClass *event_context_class = (SPEventContextClass *) klass;
91     parent_class = (SPEventContextClass *) g_type_class_peek_parent(klass);
93     object_class->dispose = sp_box3d_context_dispose;
95     event_context_class->setup = sp_box3d_context_setup;
96     event_context_class->finish = sp_box3d_context_finish;
97     event_context_class->root_handler  = sp_box3d_context_root_handler;
98     event_context_class->item_handler  = sp_box3d_context_item_handler;
99 }
101 static void sp_box3d_context_init(Box3DContext *box3d_context)
103     SPEventContext *event_context = SP_EVENT_CONTEXT(box3d_context);
105     event_context->cursor_shape = cursor_3dbox_xpm;
106     event_context->hot_x = 4;
107     event_context->hot_y = 4;
108     event_context->xp = 0;
109     event_context->yp = 0;
110     event_context->tolerance = 0;
111     event_context->within_tolerance = false;
112     event_context->item_to_select = NULL;
114     box3d_context->item = NULL;
116     box3d_context->ctrl_dragged = false;
117     box3d_context->extruded = false;
119     box3d_context->_vpdrag = NULL;
121     new (&box3d_context->sel_changed_connection) sigc::connection();
124 static void sp_box3d_context_finish(SPEventContext *ec)
126     Box3DContext *bc = SP_BOX3D_CONTEXT(ec);
127     SPDesktop *desktop = ec->desktop;
129     sp_canvas_item_ungrab(SP_CANVAS_ITEM(desktop->acetate), GDK_CURRENT_TIME);
130     sp_box3d_finish(bc);
131     bc->sel_changed_connection.disconnect();
132 //    sp_repr_remove_listener_by_data(cc->active_shape_repr, cc);
134     if (((SPEventContextClass *) parent_class)->finish) {
135         ((SPEventContextClass *) parent_class)->finish(ec);
136     }
140 static void sp_box3d_context_dispose(GObject *object)
142     Box3DContext *bc = SP_BOX3D_CONTEXT(object);
143     SPEventContext *ec = SP_EVENT_CONTEXT(object);
145     ec->enableGrDrag(false);
147     delete (bc->_vpdrag);
148     bc->_vpdrag = NULL;
150     bc->sel_changed_connection.disconnect();
151     bc->sel_changed_connection.~connection();
153     delete ec->shape_editor;
154     ec->shape_editor = NULL;
156     /* fixme: This is necessary because we do not grab */
157     if (bc->item) {
158         sp_box3d_finish(bc);
159     }
161     if (bc->_message_context) {
162         delete bc->_message_context;
163     }
165     G_OBJECT_CLASS(parent_class)->dispose(object);
168 /**
169 \brief  Callback that processes the "changed" signal on the selection;
170 destroys old and creates new knotholder
171 */
172 static void sp_box3d_context_selection_changed(Inkscape::Selection *selection, gpointer data)
174     Box3DContext *bc = SP_BOX3D_CONTEXT(data);
175     SPEventContext *ec = SP_EVENT_CONTEXT(bc);
177     ec->shape_editor->unset_item(SH_KNOTHOLDER);
178     SPItem *item = selection->singleItem();
179     ec->shape_editor->set_item(item, SH_KNOTHOLDER);
181     if (selection->perspList().size() == 1) {
182         // selecting a single box changes the current perspective
183         ec->desktop->doc()->setCurrentPersp3D(selection->perspList().front());
184     }
187 /* Create a default perspective in document defs if none is present (which can happen, among other
188  * circumstances, after 'vacuum defs' or when a pre-0.46 file is opened).
189  */
190 static void sp_box3d_context_ensure_persp_in_defs(SPDocument *document) {
191     SPDefs *defs = (SPDefs *) SP_DOCUMENT_DEFS(document);
193     bool has_persp = false;
194     for (SPObject *child = sp_object_first_child(defs); child != NULL; child = SP_OBJECT_NEXT(child) ) {
195         if (SP_IS_PERSP3D(child)) {
196             has_persp = true;
197             break;
198         }
199     }
201     if (!has_persp) {
202         document->setCurrentPersp3D(persp3d_create_xml_element (document));
203     }
206 static void sp_box3d_context_setup(SPEventContext *ec)
208     Box3DContext *bc = SP_BOX3D_CONTEXT(ec);
210     if (((SPEventContextClass *) parent_class)->setup) {
211         ((SPEventContextClass *) parent_class)->setup(ec);
212     }
214     ec->shape_editor = new ShapeEditor(ec->desktop);
216     SPItem *item = sp_desktop_selection(ec->desktop)->singleItem();
217     if (item) {
218         ec->shape_editor->set_item(item, SH_KNOTHOLDER);
219     }
221     bc->sel_changed_connection.disconnect();
222     bc->sel_changed_connection = sp_desktop_selection(ec->desktop)->connectChanged(
223         sigc::bind(sigc::ptr_fun(&sp_box3d_context_selection_changed), (gpointer)bc)
224     );
226     bc->_vpdrag = new Box3D::VPDrag(sp_desktop_document (ec->desktop));
227     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
229     if (prefs->getBool("/tools/shapes/selcue")) {
230         ec->enableSelectionCue();
231     }
233     if (prefs->getBool("/tools/shapes/gradientdrag")) {
234         ec->enableGrDrag();
235     }
237     bc->_message_context = new Inkscape::MessageContext((ec->desktop)->messageStack());
240 static gint sp_box3d_context_item_handler(SPEventContext *event_context, SPItem *item, GdkEvent *event)
242     SPDesktop *desktop = event_context->desktop;
244     gint ret = FALSE;
246     switch (event->type) {
247     case GDK_BUTTON_PRESS:
248         if ( event->button.button == 1 && !event_context->space_panning) {
249             Inkscape::setup_for_drag_start(desktop, event_context, event);
250             ret = TRUE;
251         }
252         break;
253         // motion and release are always on root (why?)
254     default:
255         break;
256     }
258     if (((SPEventContextClass *) parent_class)->item_handler) {
259         ret = ((SPEventContextClass *) parent_class)->item_handler(event_context, item, event);
260     }
262     return ret;
265 static gint sp_box3d_context_root_handler(SPEventContext *event_context, GdkEvent *event)
267     static bool dragging;
269     SPDesktop *desktop = event_context->desktop;
270     SPDocument *document = sp_desktop_document (desktop);
271     Inkscape::Selection *selection = sp_desktop_selection (desktop);
272     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
273     int const snaps = prefs->getInt("/options/rotationsnapsperpi/value", 12);
275     Box3DContext *bc = SP_BOX3D_CONTEXT(event_context);
276     Persp3D *cur_persp = document->getCurrentPersp3D();
278     event_context->tolerance = prefs->getIntLimited("/options/dragtolerance/value", 0, 0, 100);
280     gint ret = FALSE;
281     switch (event->type) {
282     case GDK_BUTTON_PRESS:
283         if ( event->button.button == 1  && !event_context->space_panning) {
284             Geom::Point const button_w(event->button.x,
285                                        event->button.y);
287             // save drag origin
288             event_context->xp = (gint) button_w[Geom::X];
289             event_context->yp = (gint) button_w[Geom::Y];
290             event_context->within_tolerance = true;
292             // remember clicked item, *not* disregarding groups (since a 3D box is a group), honoring Alt
293             event_context->item_to_select = sp_event_context_find_item (desktop, button_w, event->button.state & GDK_MOD1_MASK, event->button.state & GDK_CONTROL_MASK);
295             dragging = true;
297             /*  */
298             Geom::Point button_dt(desktop->w2d(button_w));
299             bc->drag_origin = from_2geom(button_dt);
300             bc->drag_ptB = from_2geom(button_dt);
301             bc->drag_ptC = from_2geom(button_dt);
303             // This can happen after saving when the last remaining perspective was purged and must be recreated.
304             if (!cur_persp) {
305                 sp_box3d_context_ensure_persp_in_defs(document);
306                 cur_persp = document->getCurrentPersp3D();
307             }
309             /* Projective preimages of clicked point under current perspective */
310             bc->drag_origin_proj = cur_persp->perspective_impl->tmat.preimage (from_2geom(button_dt), 0, Proj::Z);
311             bc->drag_ptB_proj = bc->drag_origin_proj;
312             bc->drag_ptC_proj = bc->drag_origin_proj;
313             bc->drag_ptC_proj.normalize();
314             bc->drag_ptC_proj[Proj::Z] = 0.25;
316             /* Snap center */
317             SnapManager &m = desktop->namedview->snap_manager;
318             m.setup(desktop, true, bc->item);
319             m.freeSnapReturnByRef(Inkscape::SnapPreferences::SNAPPOINT_NODE, button_dt, Inkscape::SNAPSOURCE_HANDLE);
320             bc->center = from_2geom(button_dt);
322             sp_canvas_item_grab(SP_CANVAS_ITEM(desktop->acetate),
323                                 ( GDK_KEY_PRESS_MASK |
324                                   GDK_BUTTON_RELEASE_MASK       |
325                                   GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK       |
326                                   GDK_BUTTON_PRESS_MASK ),
327                                 NULL, event->button.time);
328             ret = TRUE;
329         }
330         break;
331     case GDK_MOTION_NOTIFY:
332         if ( dragging
333              && ( event->motion.state & GDK_BUTTON1_MASK )  && !event_context->space_panning)
334         {
335             if ( event_context->within_tolerance
336                  && ( abs( (gint) event->motion.x - event_context->xp ) < event_context->tolerance )
337                  && ( abs( (gint) event->motion.y - event_context->yp ) < event_context->tolerance ) ) {
338                 break; // do not drag if we're within tolerance from origin
339             }
340             // Once the user has moved farther than tolerance from the original location
341             // (indicating they intend to draw, not click), then always process the
342             // motion notify coordinates as given (no snapping back to origin)
343             event_context->within_tolerance = false;
345             Geom::Point const motion_w(event->motion.x,
346                                        event->motion.y);
347             Geom::Point motion_dt(desktop->w2d(motion_w));
349             SnapManager &m = desktop->namedview->snap_manager;
350             m.setup(desktop, true, bc->item);
351             m.freeSnapReturnByRef(Inkscape::SnapPreferences::SNAPPOINT_NODE, motion_dt, Inkscape::SNAPSOURCE_HANDLE);
353             bc->ctrl_dragged  = event->motion.state & GDK_CONTROL_MASK;
355             if (event->motion.state & GDK_SHIFT_MASK && !bc->extruded && bc->item) {
356                 // once shift is pressed, set bc->extruded
357                 bc->extruded = true;
358             }
360             if (!bc->extruded) {
361                 bc->drag_ptB = from_2geom(motion_dt);
362                 bc->drag_ptC = from_2geom(motion_dt);
364                 bc->drag_ptB_proj = cur_persp->perspective_impl->tmat.preimage (from_2geom(motion_dt), 0, Proj::Z);
365                 bc->drag_ptC_proj = bc->drag_ptB_proj;
366                 bc->drag_ptC_proj.normalize();
367                 bc->drag_ptC_proj[Proj::Z] = 0.25;
368             } else {
369                 // Without Ctrl, motion of the extruded corner is constrained to the
370                 // perspective line from drag_ptB to vanishing point Y.
371                 if (!bc->ctrl_dragged) {
372                     /* snapping */
373                     Box3D::PerspectiveLine pline (bc->drag_ptB, Proj::Z, document->getCurrentPersp3D());
374                     bc->drag_ptC = pline.closest_to (from_2geom(motion_dt));
376                     bc->drag_ptB_proj.normalize();
377                     bc->drag_ptC_proj = cur_persp->perspective_impl->tmat.preimage (bc->drag_ptC, bc->drag_ptB_proj[Proj::X], Proj::X);
378                 } else {
379                     bc->drag_ptC = from_2geom(motion_dt);
381                     bc->drag_ptB_proj.normalize();
382                     bc->drag_ptC_proj = cur_persp->perspective_impl->tmat.preimage (from_2geom(motion_dt), bc->drag_ptB_proj[Proj::X], Proj::X);
383                 }
384                 Geom::Point pt2g = to_2geom(bc->drag_ptC);
385                 m.freeSnapReturnByRef(Inkscape::SnapPreferences::SNAPPOINT_NODE, pt2g, Inkscape::SNAPSOURCE_HANDLE);
386                 bc->drag_ptC = from_2geom(pt2g);
387             }
389             sp_box3d_drag(*bc, event->motion.state);
391             ret = TRUE;
392         }
393         break;
394     case GDK_BUTTON_RELEASE:
395         event_context->xp = event_context->yp = 0;
396         if ( event->button.button == 1  && !event_context->space_panning) {
397             dragging = false;
398             sp_event_context_discard_delayed_snap_event(event_context);
400             if (!event_context->within_tolerance) {
401                 // we've been dragging, finish the box
402                 sp_box3d_finish(bc);
403             } else if (event_context->item_to_select) {
404                 // no dragging, select clicked item if any
405                 if (event->button.state & GDK_SHIFT_MASK) {
406                     selection->toggle(event_context->item_to_select);
407                 } else {
408                     selection->set(event_context->item_to_select);
409                 }
410             } else {
411                 // click in an empty space
412                 selection->clear();
413             }
415             event_context->item_to_select = NULL;
416             ret = TRUE;
417             sp_canvas_item_ungrab(SP_CANVAS_ITEM(desktop->acetate),
418                                   event->button.time);
419         }
420         break;
421     case GDK_KEY_PRESS:
422         switch (get_group0_keyval (&event->key)) {
423         case GDK_Up:
424         case GDK_Down:
425         case GDK_KP_Up:
426         case GDK_KP_Down:
427             // prevent the zoom field from activation
428             if (!MOD__CTRL_ONLY)
429                 ret = TRUE;
430             break;
432         case GDK_bracketright:
433             persp3d_rotate_VP (document->getCurrentPersp3D(), Proj::X, -180/snaps, MOD__ALT);
434             sp_document_done(document, SP_VERB_CONTEXT_3DBOX,
435                              _("Change perspective (angle of PLs)"));
436             ret = true;
437             break;
439         case GDK_bracketleft:
440             persp3d_rotate_VP (document->getCurrentPersp3D(), Proj::X, 180/snaps, MOD__ALT);
441             sp_document_done(document, SP_VERB_CONTEXT_3DBOX,
442                              _("Change perspective (angle of PLs)"));
443             ret = true;
444             break;
446         case GDK_parenright:
447             persp3d_rotate_VP (document->getCurrentPersp3D(), Proj::Y, -180/snaps, MOD__ALT);
448             sp_document_done(document, SP_VERB_CONTEXT_3DBOX,
449                              _("Change perspective (angle of PLs)"));
450             ret = true;
451             break;
453         case GDK_parenleft:
454             persp3d_rotate_VP (document->getCurrentPersp3D(), Proj::Y, 180/snaps, MOD__ALT);
455             sp_document_done(document, SP_VERB_CONTEXT_3DBOX,
456                              _("Change perspective (angle of PLs)"));
457             ret = true;
458             break;
460         case GDK_braceright:
461             persp3d_rotate_VP (document->getCurrentPersp3D(), Proj::Z, -180/snaps, MOD__ALT);
462             sp_document_done(document, SP_VERB_CONTEXT_3DBOX,
463                              _("Change perspective (angle of PLs)"));
464             ret = true;
465             break;
467         case GDK_braceleft:
468             persp3d_rotate_VP (document->getCurrentPersp3D(), Proj::Z, 180/snaps, MOD__ALT);
469             sp_document_done(document, SP_VERB_CONTEXT_3DBOX,
470                              _("Change perspective (angle of PLs)"));
471             ret = true;
472             break;
474         /* TODO: what is this???
475         case GDK_O:
476             if (MOD__CTRL && MOD__SHIFT) {
477                 Box3D::create_canvas_point(persp3d_get_VP(document()->getCurrentPersp3D(), Proj::W).affine(),
478                                            6, 0xff00ff00);
479             }
480             ret = true;
481             break;
482         */
484         case GDK_g:
485         case GDK_G:
486             if (MOD__SHIFT_ONLY) {
487                 sp_selection_to_guides(desktop);
488                 ret = true;
489             }
490             break;
492         case GDK_p:
493         case GDK_P:
494             if (MOD__SHIFT_ONLY) {
495                 if (document->getCurrentPersp3D()) {
496                     persp3d_print_debugging_info (document->getCurrentPersp3D());
497                 }
498                 ret = true;
499             }
500             break;
502         case GDK_x:
503         case GDK_X:
504             if (MOD__ALT_ONLY) {
505                 desktop->setToolboxFocusTo ("altx-box3d");
506                 ret = TRUE;
507             }
508             if (MOD__SHIFT_ONLY) {
509                 persp3d_toggle_VPs(selection->perspList(), Proj::X);
510                 bc->_vpdrag->updateLines(); // FIXME: Shouldn't this be done automatically?
511                 ret = true;
512             }
513             break;
515         case GDK_y:
516         case GDK_Y:
517             if (MOD__SHIFT_ONLY) {
518                 persp3d_toggle_VPs(selection->perspList(), Proj::Y);
519                 bc->_vpdrag->updateLines(); // FIXME: Shouldn't this be done automatically?
520                 ret = true;
521             }
522             break;
524         case GDK_z:
525         case GDK_Z:
526             if (MOD__SHIFT_ONLY) {
527                 persp3d_toggle_VPs(selection->perspList(), Proj::Z);
528                 bc->_vpdrag->updateLines(); // FIXME: Shouldn't this be done automatically?
529                 ret = true;
530             }
531             break;
533         case GDK_Escape:
534             sp_desktop_selection(desktop)->clear();
535             //TODO: make dragging escapable by Esc
536             break;
538         case GDK_space:
539             if (dragging) {
540                 sp_canvas_item_ungrab(SP_CANVAS_ITEM(desktop->acetate),
541                                       event->button.time);
542                 dragging = false;
543                 sp_event_context_discard_delayed_snap_event(event_context);
544                 if (!event_context->within_tolerance) {
545                     // we've been dragging, finish the box
546                     sp_box3d_finish(bc);
547                 }
548                 // do not return true, so that space would work switching to selector
549             }
550             break;
552         default:
553             break;
554         }
555         break;
556     default:
557         break;
558     }
560     if (!ret) {
561         if (((SPEventContextClass *) parent_class)->root_handler) {
562             ret = ((SPEventContextClass *) parent_class)->root_handler(event_context, event);
563         }
564     }
566     return ret;
569 static void sp_box3d_drag(Box3DContext &bc, guint /*state*/)
571     SPDesktop *desktop = SP_EVENT_CONTEXT(&bc)->desktop;
573     if (!bc.item) {
575         if (Inkscape::have_viable_layer(desktop, bc._message_context) == false) {
576             return;
577         }
579         /* Create object */
580         Inkscape::XML::Document *xml_doc = sp_document_repr_doc(SP_EVENT_CONTEXT_DOCUMENT(&bc));
581         Inkscape::XML::Node *repr = xml_doc->createElement("svg:g");
582         repr->setAttribute("sodipodi:type", "inkscape:box3d");
584         /* Set style */
585         sp_desktop_apply_style_tool (desktop, repr, "/tools/shapes/3dbox", false);
587         bc.item = (SPItem *) desktop->currentLayer()->appendChildRepr(repr);
588         Inkscape::GC::release(repr);
589         Inkscape::XML::Node *repr_side;
590         // TODO: Incorporate this in box3d-side.cpp!
591         for (int i = 0; i < 6; ++i) {
592             repr_side = xml_doc->createElement("svg:path");
593             repr_side->setAttribute("sodipodi:type", "inkscape:box3dside");
594             repr->addChild(repr_side, NULL);
596             Box3DSide *side = SP_BOX3D_SIDE(inkscape_active_document()->getObjectByRepr (repr_side));
598             guint desc = Box3D::int_to_face(i);
600             Box3D::Axis plane = (Box3D::Axis) (desc & 0x7);
601             plane = (Box3D::is_plane(plane) ? plane : Box3D::orth_plane_or_axis(plane));
602             side->dir1 = Box3D::extract_first_axis_direction(plane);
603             side->dir2 = Box3D::extract_second_axis_direction(plane);
604             side->front_or_rear = (Box3D::FrontOrRear) (desc & 0x8);
606             /* Set style */
607             box3d_side_apply_style(side);
609             SP_OBJECT(side)->updateRepr(); // calls box3d_side_write() and updates, e.g., the axes string description
610         }
612         box3d_set_z_orders(SP_BOX3D(bc.item));
613         bc.item->updateRepr();
615         // TODO: It would be nice to show the VPs during dragging, but since there is no selection
616         //       at this point (only after finishing the box), we must do this "manually"
617         /* bc._vpdrag->updateDraggers(); */
619         sp_canvas_force_full_redraw_after_interruptions(desktop->canvas, 5);
620     }
622     g_assert(bc.item);
624     SPBox3D *box = SP_BOX3D(bc.item);
626     box->orig_corner0 = bc.drag_origin_proj;
627     box->orig_corner7 = bc.drag_ptC_proj;
629     box3d_check_for_swapped_coords(box);
631     /* we need to call this from here (instead of from box3d_position_set(), for example)
632        because z-order setting must not interfere with display updates during undo/redo */
633     box3d_set_z_orders (box);
635     box3d_position_set(box);
637     // status text
638     bc._message_context->setF(Inkscape::NORMAL_MESSAGE, _("<b>3D Box</b>; with <b>Shift</b> to extrude along the Z axis"));
641 static void sp_box3d_finish(Box3DContext *bc)
643     bc->_message_context->clear();
644     bc->ctrl_dragged = false;
645     bc->extruded = false;
647     if ( bc->item != NULL ) {
648         SPDesktop * desktop = SP_EVENT_CONTEXT_DESKTOP(bc);
649         SPDocument *doc = sp_desktop_document(desktop);
650         if (!doc || !doc->getCurrentPersp3D())
651             return;
653         SPBox3D *box = SP_BOX3D(bc->item);
655         box->orig_corner0 = bc->drag_origin_proj;
656         box->orig_corner7 = bc->drag_ptC_proj;
658         box->updateRepr();
660         box3d_relabel_corners(box);
662         sp_canvas_end_forced_full_redraws(desktop->canvas);
664         sp_desktop_selection(desktop)->set(bc->item);
665         sp_document_done(sp_desktop_document(desktop), SP_VERB_CONTEXT_3DBOX,
666                          _("Create 3D box"));
668         bc->item = NULL;
669     }
672 void sp_box3d_context_update_lines(SPEventContext *ec) {
673     /*  update perspective lines if we are in the 3D box tool (so that infinite ones are shown correctly) */
674     if (SP_IS_BOX3D_CONTEXT (ec)) {
675         Box3DContext *bc = SP_BOX3D_CONTEXT (ec);
676         bc->_vpdrag->updateLines();
677     }
680 /*
681   Local Variables:
682   mode:c++
683   c-file-style:"stroustrup"
684   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
685   indent-tabs-mode:nil
686   fill-column:99
687   End:
688 */
689 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :