~centralelyon2010/inkscape/imagelinks2

3084 by cilix42
First (very limited) version of the 3D box tool; allows for drawing of new boxes in a fixed perspective without any live interaction.
1
/*
2
 * 3D box drawing context
3
 *
4
 * Author:
5
 *   Lauris Kaplinski <lauris@kaplinski.com>
6
 *   bulia byak <buliabyak@users.sf.net>
9020 by JazzyNico
Code refactoring and merging with trunk (revision 10599).
7
 *   Jon A. Cruz <jon@joncruz.org>
8
 *   Abhishek Sharma
3084 by cilix42
First (very limited) version of the 3D box tool; allows for drawing of new boxes in a fixed perspective without any live interaction.
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
 */
17
18
#include "config.h"
19
20
#include <gdk/gdkkeysyms.h>
21
22
#include "macros.h"
23
#include "display/sp-canvas.h"
24
#include "document.h"
25
#include "sp-namedview.h"
26
#include "selection.h"
4462 by cilix42
Add possibility to convert objects (only rectangles and 3D boxes currently) to guidelines. Also see corresponding post on the mailing list; in particular, feel free to revert it if this is inappropriate during Frost phase.
27
#include "selection-chemistry.h"
3084 by cilix42
First (very limited) version of the 3D box tool; allows for drawing of new boxes in a fixed perspective without any live interaction.
28
#include "desktop-handles.h"
29
#include "snap.h"
30
#include "display/curve.h"
31
#include "desktop.h"
32
#include "message-context.h"
3825 by buliabyak
3dbox cursor
33
#include "pixmaps/cursor-3dbox.xpm"
3084 by cilix42
First (very limited) version of the 3D box tool; allows for drawing of new boxes in a fixed perspective without any live interaction.
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"
6885 by Ted Gould
From trunk
41
#include "preferences.h"
3084 by cilix42
First (very limited) version of the 3D box tool; allows for drawing of new boxes in a fixed perspective without any live interaction.
42
#include "context-fns.h"
4224 by cilix42
Fundamentally reworked version of the 3D box tool (among many other things, this fixes bugs #168900 and #168868). See mailing list for details. Sorry for this single large commit but it was unfeasible to keep the history.
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"
4824 by cilix42
Clean up comments and remove (already commented) debugging messages
48
#include "document-private.h"
4224 by cilix42
Fundamentally reworked version of the 3D box tool (among many other things, this fixes bugs #168900 and #168868). See mailing list for details. Sorry for this single large commit but it was unfeasible to keep the history.
49
#include "line-geometry.h"
7097 by buliabyak
switch to using shape_editor, instead of separate knotholders and listeners; fixes a lot of crashes, simplifies code
50
#include "shape-editor.h"
4224 by cilix42
Fundamentally reworked version of the 3D box tool (among many other things, this fixes bugs #168900 and #168868). See mailing list for details. Sorry for this single large commit but it was unfeasible to keep the history.
51
9020 by JazzyNico
Code refactoring and merging with trunk (revision 10599).
52
using Inkscape::DocumentUndo;
53
4224 by cilix42
Fundamentally reworked version of the 3D box tool (among many other things, this fixes bugs #168900 and #168868). See mailing list for details. Sorry for this single large commit but it was unfeasible to keep the history.
54
static void sp_box3d_context_class_init(Box3DContextClass *klass);
55
static void sp_box3d_context_init(Box3DContext *box3d_context);
56
static void sp_box3d_context_dispose(GObject *object);
57
58
static void sp_box3d_context_setup(SPEventContext *ec);
8375 by dvlierop2
When switching context by pressing a key, while dragging to create a new shape, the original context should be finished properly and sp_canvas_item_ungrab should be called. set_event_context() was looking for e.g. sp_rect_context_finish, but this wasn't implemented for any of the shape tools. This closes bug #195101
59
static void sp_box3d_context_finish(SPEventContext *ec);
4224 by cilix42
Fundamentally reworked version of the 3D box tool (among many other things, this fixes bugs #168900 and #168868). See mailing list for details. Sorry for this single large commit but it was unfeasible to keep the history.
60
61
static gint sp_box3d_context_root_handler(SPEventContext *event_context, GdkEvent *event);
62
static gint sp_box3d_context_item_handler(SPEventContext *event_context, SPItem *item, GdkEvent *event);
63
64
static void sp_box3d_drag(Box3DContext &bc, guint state);
65
static void sp_box3d_finish(Box3DContext *bc);
3084 by cilix42
First (very limited) version of the 3D box tool; allows for drawing of new boxes in a fixed perspective without any live interaction.
66
67
static SPEventContextClass *parent_class;
68
9020 by JazzyNico
Code refactoring and merging with trunk (revision 10599).
69
GType sp_box3d_context_get_type()
3084 by cilix42
First (very limited) version of the 3D box tool; allows for drawing of new boxes in a fixed perspective without any live interaction.
70
{
71
    static GType type = 0;
72
    if (!type) {
73
        GTypeInfo info = {
4224 by cilix42
Fundamentally reworked version of the 3D box tool (among many other things, this fixes bugs #168900 and #168868). See mailing list for details. Sorry for this single large commit but it was unfeasible to keep the history.
74
            sizeof(Box3DContextClass),
75
            NULL, NULL,
76
            (GClassInitFunc) sp_box3d_context_class_init,
77
            NULL, NULL,
78
            sizeof(Box3DContext),
3084 by cilix42
First (very limited) version of the 3D box tool; allows for drawing of new boxes in a fixed perspective without any live interaction.
79
            4,
4224 by cilix42
Fundamentally reworked version of the 3D box tool (among many other things, this fixes bugs #168900 and #168868). See mailing list for details. Sorry for this single large commit but it was unfeasible to keep the history.
80
            (GInstanceInitFunc) sp_box3d_context_init,
3084 by cilix42
First (very limited) version of the 3D box tool; allows for drawing of new boxes in a fixed perspective without any live interaction.
81
            NULL,    /* value_table */
82
        };
4224 by cilix42
Fundamentally reworked version of the 3D box tool (among many other things, this fixes bugs #168900 and #168868). See mailing list for details. Sorry for this single large commit but it was unfeasible to keep the history.
83
        type = g_type_register_static(SP_TYPE_EVENT_CONTEXT, "Box3DContext", &info, (GTypeFlags) 0);
3084 by cilix42
First (very limited) version of the 3D box tool; allows for drawing of new boxes in a fixed perspective without any live interaction.
84
    }
85
    return type;
86
}
87
4224 by cilix42
Fundamentally reworked version of the 3D box tool (among many other things, this fixes bugs #168900 and #168868). See mailing list for details. Sorry for this single large commit but it was unfeasible to keep the history.
88
static void sp_box3d_context_class_init(Box3DContextClass *klass)
3084 by cilix42
First (very limited) version of the 3D box tool; allows for drawing of new boxes in a fixed perspective without any live interaction.
89
{
90
    GObjectClass *object_class = (GObjectClass *) klass;
91
    SPEventContextClass *event_context_class = (SPEventContextClass *) klass;
92
93
    parent_class = (SPEventContextClass *) g_type_class_peek_parent(klass);
94
4224 by cilix42
Fundamentally reworked version of the 3D box tool (among many other things, this fixes bugs #168900 and #168868). See mailing list for details. Sorry for this single large commit but it was unfeasible to keep the history.
95
    object_class->dispose = sp_box3d_context_dispose;
3084 by cilix42
First (very limited) version of the 3D box tool; allows for drawing of new boxes in a fixed perspective without any live interaction.
96
4224 by cilix42
Fundamentally reworked version of the 3D box tool (among many other things, this fixes bugs #168900 and #168868). See mailing list for details. Sorry for this single large commit but it was unfeasible to keep the history.
97
    event_context_class->setup = sp_box3d_context_setup;
8375 by dvlierop2
When switching context by pressing a key, while dragging to create a new shape, the original context should be finished properly and sp_canvas_item_ungrab should be called. set_event_context() was looking for e.g. sp_rect_context_finish, but this wasn't implemented for any of the shape tools. This closes bug #195101
98
    event_context_class->finish = sp_box3d_context_finish;
4224 by cilix42
Fundamentally reworked version of the 3D box tool (among many other things, this fixes bugs #168900 and #168868). See mailing list for details. Sorry for this single large commit but it was unfeasible to keep the history.
99
    event_context_class->root_handler  = sp_box3d_context_root_handler;
100
    event_context_class->item_handler  = sp_box3d_context_item_handler;
3084 by cilix42
First (very limited) version of the 3D box tool; allows for drawing of new boxes in a fixed perspective without any live interaction.
101
}
102
4224 by cilix42
Fundamentally reworked version of the 3D box tool (among many other things, this fixes bugs #168900 and #168868). See mailing list for details. Sorry for this single large commit but it was unfeasible to keep the history.
103
static void sp_box3d_context_init(Box3DContext *box3d_context)
3084 by cilix42
First (very limited) version of the 3D box tool; allows for drawing of new boxes in a fixed perspective without any live interaction.
104
{
105
    SPEventContext *event_context = SP_EVENT_CONTEXT(box3d_context);
106
3825 by buliabyak
3dbox cursor
107
    event_context->cursor_shape = cursor_3dbox_xpm;
3084 by cilix42
First (very limited) version of the 3D box tool; allows for drawing of new boxes in a fixed perspective without any live interaction.
108
    event_context->hot_x = 4;
109
    event_context->hot_y = 4;
110
    event_context->xp = 0;
111
    event_context->yp = 0;
112
    event_context->tolerance = 0;
113
    event_context->within_tolerance = false;
114
    event_context->item_to_select = NULL;
115
116
    box3d_context->item = NULL;
117
118
    box3d_context->ctrl_dragged = false;
119
    box3d_context->extruded = false;
7172 by dvlierop2
- The snap-delay mechanism should now be more robust. From now on, it must be turned on and off explicitely within each context. This prevents delayed snapping events from being fired after the context or context's state has changed.
120
3391 by cilix42
First stage of draggable vanishing points (no snapping/unsnapping yet)
121
    box3d_context->_vpdrag = NULL;
122
3084 by cilix42
First (very limited) version of the 3D box tool; allows for drawing of new boxes in a fixed perspective without any live interaction.
123
    new (&box3d_context->sel_changed_connection) sigc::connection();
124
}
125
8375 by dvlierop2
When switching context by pressing a key, while dragging to create a new shape, the original context should be finished properly and sp_canvas_item_ungrab should be called. set_event_context() was looking for e.g. sp_rect_context_finish, but this wasn't implemented for any of the shape tools. This closes bug #195101
126
static void sp_box3d_context_finish(SPEventContext *ec)
127
{
8910 by Maximilian Albert
Refactoring of 3D box tool, mainly to avoid unnecessary creation of perspectives.
128
    Box3DContext *bc = SP_BOX3D_CONTEXT(ec);
129
    SPDesktop *desktop = ec->desktop;
8375 by dvlierop2
When switching context by pressing a key, while dragging to create a new shape, the original context should be finished properly and sp_canvas_item_ungrab should be called. set_event_context() was looking for e.g. sp_rect_context_finish, but this wasn't implemented for any of the shape tools. This closes bug #195101
130
8910 by Maximilian Albert
Refactoring of 3D box tool, mainly to avoid unnecessary creation of perspectives.
131
    sp_canvas_item_ungrab(SP_CANVAS_ITEM(desktop->acetate), GDK_CURRENT_TIME);
132
    sp_box3d_finish(bc);
8375 by dvlierop2
When switching context by pressing a key, while dragging to create a new shape, the original context should be finished properly and sp_canvas_item_ungrab should be called. set_event_context() was looking for e.g. sp_rect_context_finish, but this wasn't implemented for any of the shape tools. This closes bug #195101
133
    bc->sel_changed_connection.disconnect();
8910 by Maximilian Albert
Refactoring of 3D box tool, mainly to avoid unnecessary creation of perspectives.
134
//    sp_repr_remove_listener_by_data(cc->active_shape_repr, cc);
8375 by dvlierop2
When switching context by pressing a key, while dragging to create a new shape, the original context should be finished properly and sp_canvas_item_ungrab should be called. set_event_context() was looking for e.g. sp_rect_context_finish, but this wasn't implemented for any of the shape tools. This closes bug #195101
135
136
    if (((SPEventContextClass *) parent_class)->finish) {
8910 by Maximilian Albert
Refactoring of 3D box tool, mainly to avoid unnecessary creation of perspectives.
137
        ((SPEventContextClass *) parent_class)->finish(ec);
138
    }
8375 by dvlierop2
When switching context by pressing a key, while dragging to create a new shape, the original context should be finished properly and sp_canvas_item_ungrab should be called. set_event_context() was looking for e.g. sp_rect_context_finish, but this wasn't implemented for any of the shape tools. This closes bug #195101
139
}
140
141
4224 by cilix42
Fundamentally reworked version of the 3D box tool (among many other things, this fixes bugs #168900 and #168868). See mailing list for details. Sorry for this single large commit but it was unfeasible to keep the history.
142
static void sp_box3d_context_dispose(GObject *object)
3084 by cilix42
First (very limited) version of the 3D box tool; allows for drawing of new boxes in a fixed perspective without any live interaction.
143
{
4224 by cilix42
Fundamentally reworked version of the 3D box tool (among many other things, this fixes bugs #168900 and #168868). See mailing list for details. Sorry for this single large commit but it was unfeasible to keep the history.
144
    Box3DContext *bc = SP_BOX3D_CONTEXT(object);
3084 by cilix42
First (very limited) version of the 3D box tool; allows for drawing of new boxes in a fixed perspective without any live interaction.
145
    SPEventContext *ec = SP_EVENT_CONTEXT(object);
146
147
    ec->enableGrDrag(false);
148
3391 by cilix42
First stage of draggable vanishing points (no snapping/unsnapping yet)
149
    delete (bc->_vpdrag);
150
    bc->_vpdrag = NULL;
151
3385 by cilix42
Cosmetic
152
    bc->sel_changed_connection.disconnect();
153
    bc->sel_changed_connection.~connection();
3084 by cilix42
First (very limited) version of the 3D box tool; allows for drawing of new boxes in a fixed perspective without any live interaction.
154
7097 by buliabyak
switch to using shape_editor, instead of separate knotholders and listeners; fixes a lot of crashes, simplifies code
155
    delete ec->shape_editor;
156
    ec->shape_editor = NULL;
157
3084 by cilix42
First (very limited) version of the 3D box tool; allows for drawing of new boxes in a fixed perspective without any live interaction.
158
    /* fixme: This is necessary because we do not grab */
3385 by cilix42
Cosmetic
159
    if (bc->item) {
4224 by cilix42
Fundamentally reworked version of the 3D box tool (among many other things, this fixes bugs #168900 and #168868). See mailing list for details. Sorry for this single large commit but it was unfeasible to keep the history.
160
        sp_box3d_finish(bc);
3084 by cilix42
First (very limited) version of the 3D box tool; allows for drawing of new boxes in a fixed perspective without any live interaction.
161
    }
162
3385 by cilix42
Cosmetic
163
    if (bc->_message_context) {
164
        delete bc->_message_context;
3084 by cilix42
First (very limited) version of the 3D box tool; allows for drawing of new boxes in a fixed perspective without any live interaction.
165
    }
166
167
    G_OBJECT_CLASS(parent_class)->dispose(object);
168
}
169
170
/**
171
\brief  Callback that processes the "changed" signal on the selection;
172
destroys old and creates new knotholder
173
*/
4224 by cilix42
Fundamentally reworked version of the 3D box tool (among many other things, this fixes bugs #168900 and #168868). See mailing list for details. Sorry for this single large commit but it was unfeasible to keep the history.
174
static void sp_box3d_context_selection_changed(Inkscape::Selection *selection, gpointer data)
3084 by cilix42
First (very limited) version of the 3D box tool; allows for drawing of new boxes in a fixed perspective without any live interaction.
175
{
4224 by cilix42
Fundamentally reworked version of the 3D box tool (among many other things, this fixes bugs #168900 and #168868). See mailing list for details. Sorry for this single large commit but it was unfeasible to keep the history.
176
    Box3DContext *bc = SP_BOX3D_CONTEXT(data);
3385 by cilix42
Cosmetic
177
    SPEventContext *ec = SP_EVENT_CONTEXT(bc);
3084 by cilix42
First (very limited) version of the 3D box tool; allows for drawing of new boxes in a fixed perspective without any live interaction.
178
7097 by buliabyak
switch to using shape_editor, instead of separate knotholders and listeners; fixes a lot of crashes, simplifies code
179
    ec->shape_editor->unset_item(SH_KNOTHOLDER);
7172 by dvlierop2
- The snap-delay mechanism should now be more robust. From now on, it must be turned on and off explicitely within each context. This prevents delayed snapping events from being fired after the context or context's state has changed.
180
    SPItem *item = selection->singleItem();
7097 by buliabyak
switch to using shape_editor, instead of separate knotholders and listeners; fixes a lot of crashes, simplifies code
181
    ec->shape_editor->set_item(item, SH_KNOTHOLDER);
4224 by cilix42
Fundamentally reworked version of the 3D box tool (among many other things, this fixes bugs #168900 and #168868). See mailing list for details. Sorry for this single large commit but it was unfeasible to keep the history.
182
5122 by cilix42
Make grouped 3D boxes work correctly when transformed (fixes: LP 188991)
183
    if (selection->perspList().size() == 1) {
4224 by cilix42
Fundamentally reworked version of the 3D box tool (among many other things, this fixes bugs #168900 and #168868). See mailing list for details. Sorry for this single large commit but it was unfeasible to keep the history.
184
        // selecting a single box changes the current perspective
8910 by Maximilian Albert
Refactoring of 3D box tool, mainly to avoid unnecessary creation of perspectives.
185
        ec->desktop->doc()->setCurrentPersp3D(selection->perspList().front());
3084 by cilix42
First (very limited) version of the 3D box tool; allows for drawing of new boxes in a fixed perspective without any live interaction.
186
    }
187
}
188
8910 by Maximilian Albert
Refactoring of 3D box tool, mainly to avoid unnecessary creation of perspectives.
189
/* Create a default perspective in document defs if none is present (which can happen, among other
190
 * circumstances, after 'vacuum defs' or when a pre-0.46 file is opened).
191
 */
192
static void sp_box3d_context_ensure_persp_in_defs(SPDocument *document) {
9020 by JazzyNico
Code refactoring and merging with trunk (revision 10599).
193
    SPDefs *defs = document->getDefs();
4461 by cilix42
Check for perspective in document defs (to avoid hanging/crashes after vacuum defs or when opening pre-0.46 documents); partly fixes LP #182031
194
195
    bool has_persp = false;
9020 by JazzyNico
Code refactoring and merging with trunk (revision 10599).
196
    for ( SPObject *child = defs->firstChild(); child; child = child->getNext() ) {
4461 by cilix42
Check for perspective in document defs (to avoid hanging/crashes after vacuum defs or when opening pre-0.46 documents); partly fixes LP #182031
197
        if (SP_IS_PERSP3D(child)) {
198
            has_persp = true;
199
            break;
200
        }
201
    }
202
203
    if (!has_persp) {
8910 by Maximilian Albert
Refactoring of 3D box tool, mainly to avoid unnecessary creation of perspectives.
204
        document->setCurrentPersp3D(persp3d_create_xml_element (document));
4461 by cilix42
Check for perspective in document defs (to avoid hanging/crashes after vacuum defs or when opening pre-0.46 documents); partly fixes LP #182031
205
    }
206
}
207
4224 by cilix42
Fundamentally reworked version of the 3D box tool (among many other things, this fixes bugs #168900 and #168868). See mailing list for details. Sorry for this single large commit but it was unfeasible to keep the history.
208
static void sp_box3d_context_setup(SPEventContext *ec)
3084 by cilix42
First (very limited) version of the 3D box tool; allows for drawing of new boxes in a fixed perspective without any live interaction.
209
{
4224 by cilix42
Fundamentally reworked version of the 3D box tool (among many other things, this fixes bugs #168900 and #168868). See mailing list for details. Sorry for this single large commit but it was unfeasible to keep the history.
210
    Box3DContext *bc = SP_BOX3D_CONTEXT(ec);
3084 by cilix42
First (very limited) version of the 3D box tool; allows for drawing of new boxes in a fixed perspective without any live interaction.
211
212
    if (((SPEventContextClass *) parent_class)->setup) {
213
        ((SPEventContextClass *) parent_class)->setup(ec);
214
    }
215
7097 by buliabyak
switch to using shape_editor, instead of separate knotholders and listeners; fixes a lot of crashes, simplifies code
216
    ec->shape_editor = new ShapeEditor(ec->desktop);
217
3084 by cilix42
First (very limited) version of the 3D box tool; allows for drawing of new boxes in a fixed perspective without any live interaction.
218
    SPItem *item = sp_desktop_selection(ec->desktop)->singleItem();
219
    if (item) {
7097 by buliabyak
switch to using shape_editor, instead of separate knotholders and listeners; fixes a lot of crashes, simplifies code
220
        ec->shape_editor->set_item(item, SH_KNOTHOLDER);
3084 by cilix42
First (very limited) version of the 3D box tool; allows for drawing of new boxes in a fixed perspective without any live interaction.
221
    }
222
3385 by cilix42
Cosmetic
223
    bc->sel_changed_connection.disconnect();
224
    bc->sel_changed_connection = sp_desktop_selection(ec->desktop)->connectChanged(
4224 by cilix42
Fundamentally reworked version of the 3D box tool (among many other things, this fixes bugs #168900 and #168868). See mailing list for details. Sorry for this single large commit but it was unfeasible to keep the history.
225
        sigc::bind(sigc::ptr_fun(&sp_box3d_context_selection_changed), (gpointer)bc)
3084 by cilix42
First (very limited) version of the 3D box tool; allows for drawing of new boxes in a fixed perspective without any live interaction.
226
    );
227
3445 by cilix42
Hold perspectives on document level rather than globally; this corrects the changes made in commit #15681
228
    bc->_vpdrag = new Box3D::VPDrag(sp_desktop_document (ec->desktop));
6885 by Ted Gould
From trunk
229
    Inkscape::Preferences *prefs = Inkscape::Preferences::get();
3391 by cilix42
First stage of draggable vanishing points (no snapping/unsnapping yet)
230
6885 by Ted Gould
From trunk
231
    if (prefs->getBool("/tools/shapes/selcue")) {
3084 by cilix42
First (very limited) version of the 3D box tool; allows for drawing of new boxes in a fixed perspective without any live interaction.
232
        ec->enableSelectionCue();
233
    }
234
6885 by Ted Gould
From trunk
235
    if (prefs->getBool("/tools/shapes/gradientdrag")) {
3084 by cilix42
First (very limited) version of the 3D box tool; allows for drawing of new boxes in a fixed perspective without any live interaction.
236
        ec->enableGrDrag();
237
    }
238
3385 by cilix42
Cosmetic
239
    bc->_message_context = new Inkscape::MessageContext((ec->desktop)->messageStack());
3084 by cilix42
First (very limited) version of the 3D box tool; allows for drawing of new boxes in a fixed perspective without any live interaction.
240
}
241
4224 by cilix42
Fundamentally reworked version of the 3D box tool (among many other things, this fixes bugs #168900 and #168868). See mailing list for details. Sorry for this single large commit but it was unfeasible to keep the history.
242
static gint sp_box3d_context_item_handler(SPEventContext *event_context, SPItem *item, GdkEvent *event)
3084 by cilix42
First (very limited) version of the 3D box tool; allows for drawing of new boxes in a fixed perspective without any live interaction.
243
{
244
    SPDesktop *desktop = event_context->desktop;
245
246
    gint ret = FALSE;
247
248
    switch (event->type) {
249
    case GDK_BUTTON_PRESS:
3341 by buliabyak
due to the order of processing events, we must disable lmb handling in children contexts so that parent event context can handle it for space panning
250
        if ( event->button.button == 1 && !event_context->space_panning) {
3084 by cilix42
First (very limited) version of the 3D box tool; allows for drawing of new boxes in a fixed perspective without any live interaction.
251
            Inkscape::setup_for_drag_start(desktop, event_context, event);
252
            ret = TRUE;
253
        }
254
        break;
255
        // motion and release are always on root (why?)
256
    default:
257
        break;
258
    }
259
260
    if (((SPEventContextClass *) parent_class)->item_handler) {
261
        ret = ((SPEventContextClass *) parent_class)->item_handler(event_context, item, event);
262
    }
263
264
    return ret;
265
}
266
4224 by cilix42
Fundamentally reworked version of the 3D box tool (among many other things, this fixes bugs #168900 and #168868). See mailing list for details. Sorry for this single large commit but it was unfeasible to keep the history.
267
static gint sp_box3d_context_root_handler(SPEventContext *event_context, GdkEvent *event)
3084 by cilix42
First (very limited) version of the 3D box tool; allows for drawing of new boxes in a fixed perspective without any live interaction.
268
{
269
    static bool dragging;
270
271
    SPDesktop *desktop = event_context->desktop;
8910 by Maximilian Albert
Refactoring of 3D box tool, mainly to avoid unnecessary creation of perspectives.
272
    SPDocument *document = sp_desktop_document (desktop);
3084 by cilix42
First (very limited) version of the 3D box tool; allows for drawing of new boxes in a fixed perspective without any live interaction.
273
    Inkscape::Selection *selection = sp_desktop_selection (desktop);
6885 by Ted Gould
From trunk
274
    Inkscape::Preferences *prefs = Inkscape::Preferences::get();
275
    int const snaps = prefs->getInt("/options/rotationsnapsperpi/value", 12);
3084 by cilix42
First (very limited) version of the 3D box tool; allows for drawing of new boxes in a fixed perspective without any live interaction.
276
4224 by cilix42
Fundamentally reworked version of the 3D box tool (among many other things, this fixes bugs #168900 and #168868). See mailing list for details. Sorry for this single large commit but it was unfeasible to keep the history.
277
    Box3DContext *bc = SP_BOX3D_CONTEXT(event_context);
8910 by Maximilian Albert
Refactoring of 3D box tool, mainly to avoid unnecessary creation of perspectives.
278
    Persp3D *cur_persp = document->getCurrentPersp3D();
3084 by cilix42
First (very limited) version of the 3D box tool; allows for drawing of new boxes in a fixed perspective without any live interaction.
279
6885 by Ted Gould
From trunk
280
    event_context->tolerance = prefs->getIntLimited("/options/dragtolerance/value", 0, 0, 100);
3084 by cilix42
First (very limited) version of the 3D box tool; allows for drawing of new boxes in a fixed perspective without any live interaction.
281
282
    gint ret = FALSE;
283
    switch (event->type) {
284
    case GDK_BUTTON_PRESS:
3341 by buliabyak
due to the order of processing events, we must disable lmb handling in children contexts so that parent event context can handle it for space panning
285
        if ( event->button.button == 1  && !event_context->space_panning) {
6837 by cilix42
More NR::Point ==> Geom::Point
286
            Geom::Point const button_w(event->button.x,
287
                                       event->button.y);
9020 by JazzyNico
Code refactoring and merging with trunk (revision 10599).
288
            Geom::Point button_dt(desktop->w2d(button_w));
3084 by cilix42
First (very limited) version of the 3D box tool; allows for drawing of new boxes in a fixed perspective without any live interaction.
289
290
            // save drag origin
6837 by cilix42
More NR::Point ==> Geom::Point
291
            event_context->xp = (gint) button_w[Geom::X];
292
            event_context->yp = (gint) button_w[Geom::Y];
3084 by cilix42
First (very limited) version of the 3D box tool; allows for drawing of new boxes in a fixed perspective without any live interaction.
293
            event_context->within_tolerance = true;
7172 by dvlierop2
- The snap-delay mechanism should now be more robust. From now on, it must be turned on and off explicitely within each context. This prevents delayed snapping events from being fired after the context or context's state has changed.
294
4224 by cilix42
Fundamentally reworked version of the 3D box tool (among many other things, this fixes bugs #168900 and #168868). See mailing list for details. Sorry for this single large commit but it was unfeasible to keep the history.
295
            // remember clicked item, *not* disregarding groups (since a 3D box is a group), honoring Alt
3210 by cilix42
Click-select entire 3D boxes instead of only single faces; faces can still be selected with (Alt+)Ctrl-Click
296
            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);
3084 by cilix42
First (very limited) version of the 3D box tool; allows for drawing of new boxes in a fixed perspective without any live interaction.
297
298
            dragging = true;
7172 by dvlierop2
- The snap-delay mechanism should now be more robust. From now on, it must be turned on and off explicitely within each context. This prevents delayed snapping events from being fired after the context or context's state has changed.
299
9020 by JazzyNico
Code refactoring and merging with trunk (revision 10599).
300
            SnapManager &m = desktop->namedview->snap_manager;
301
            m.setup(desktop, true, bc->item);
302
            m.freeSnapReturnByRef(button_dt, Inkscape::SNAPSOURCE_NODE_HANDLE);
303
            m.unSetup();
304
            bc->center = button_dt;
305
306
            bc->drag_origin = button_dt;
307
            bc->drag_ptB = button_dt;
308
            bc->drag_ptC = button_dt;
3084 by cilix42
First (very limited) version of the 3D box tool; allows for drawing of new boxes in a fixed perspective without any live interaction.
309
8910 by Maximilian Albert
Refactoring of 3D box tool, mainly to avoid unnecessary creation of perspectives.
310
            // This can happen after saving when the last remaining perspective was purged and must be recreated.
311
            if (!cur_persp) {
312
                sp_box3d_context_ensure_persp_in_defs(document);
313
                cur_persp = document->getCurrentPersp3D();
314
            }
315
4224 by cilix42
Fundamentally reworked version of the 3D box tool (among many other things, this fixes bugs #168900 and #168868). See mailing list for details. Sorry for this single large commit but it was unfeasible to keep the history.
316
            /* Projective preimages of clicked point under current perspective */
9020 by JazzyNico
Code refactoring and merging with trunk (revision 10599).
317
            bc->drag_origin_proj = cur_persp->perspective_impl->tmat.preimage (button_dt, 0, Proj::Z);
4224 by cilix42
Fundamentally reworked version of the 3D box tool (among many other things, this fixes bugs #168900 and #168868). See mailing list for details. Sorry for this single large commit but it was unfeasible to keep the history.
318
            bc->drag_ptB_proj = bc->drag_origin_proj;
319
            bc->drag_ptC_proj = bc->drag_origin_proj;
320
            bc->drag_ptC_proj.normalize();
321
            bc->drag_ptC_proj[Proj::Z] = 0.25;
322
3084 by cilix42
First (very limited) version of the 3D box tool; allows for drawing of new boxes in a fixed perspective without any live interaction.
323
            sp_canvas_item_grab(SP_CANVAS_ITEM(desktop->acetate),
324
                                ( GDK_KEY_PRESS_MASK |
325
                                  GDK_BUTTON_RELEASE_MASK       |
6222 by mental
I'm an idiot who forgot that MOTION_HINT_MASK still needs MOTION_MASK
326
                                  GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK       |
3084 by cilix42
First (very limited) version of the 3D box tool; allows for drawing of new boxes in a fixed perspective without any live interaction.
327
                                  GDK_BUTTON_PRESS_MASK ),
328
                                NULL, event->button.time);
329
            ret = TRUE;
330
        }
331
        break;
332
    case GDK_MOTION_NOTIFY:
333
        if ( dragging
3341 by buliabyak
due to the order of processing events, we must disable lmb handling in children contexts so that parent event context can handle it for space panning
334
             && ( event->motion.state & GDK_BUTTON1_MASK )  && !event_context->space_panning)
3084 by cilix42
First (very limited) version of the 3D box tool; allows for drawing of new boxes in a fixed perspective without any live interaction.
335
        {
336
            if ( event_context->within_tolerance
337
                 && ( abs( (gint) event->motion.x - event_context->xp ) < event_context->tolerance )
338
                 && ( abs( (gint) event->motion.y - event_context->yp ) < event_context->tolerance ) ) {
339
                break; // do not drag if we're within tolerance from origin
340
            }
341
            // Once the user has moved farther than tolerance from the original location
342
            // (indicating they intend to draw, not click), then always process the
343
            // motion notify coordinates as given (no snapping back to origin)
344
            event_context->within_tolerance = false;
345
6837 by cilix42
More NR::Point ==> Geom::Point
346
            Geom::Point const motion_w(event->motion.x,
347
                                       event->motion.y);
348
            Geom::Point motion_dt(desktop->w2d(motion_w));
3084 by cilix42
First (very limited) version of the 3D box tool; allows for drawing of new boxes in a fixed perspective without any live interaction.
349
5556 by dvlierop2
- Major refactoring of snapping related code...
350
            SnapManager &m = desktop->namedview->snap_manager;
6722 by dvlierop2
Modify the parameters required for setting up the SnapManager
351
            m.setup(desktop, true, bc->item);
9012.1.2 by Diederik van Lierop
Remove redundancy from snapping API (type of snapsource no longer has to be specified explicitly)
352
            m.freeSnapReturnByRef(motion_dt, Inkscape::SNAPSOURCE_NODE_HANDLE);
3385 by cilix42
Cosmetic
353
            bc->ctrl_dragged  = event->motion.state & GDK_CONTROL_MASK;
354
3601 by cilix42
Remove some warnings and fix crash in 3D box tool
355
            if (event->motion.state & GDK_SHIFT_MASK && !bc->extruded && bc->item) {
4224 by cilix42
Fundamentally reworked version of the 3D box tool (among many other things, this fixes bugs #168900 and #168868). See mailing list for details. Sorry for this single large commit but it was unfeasible to keep the history.
356
                // once shift is pressed, set bc->extruded
3385 by cilix42
Cosmetic
357
                bc->extruded = true;
3170 by cilix42
Only create the faces of a 3D box when needed (use pointers to refer to them).
358
            }
3084 by cilix42
First (very limited) version of the 3D box tool; allows for drawing of new boxes in a fixed perspective without any live interaction.
359
3385 by cilix42
Cosmetic
360
            if (!bc->extruded) {
9020 by JazzyNico
Code refactoring and merging with trunk (revision 10599).
361
                bc->drag_ptB = motion_dt;
362
                bc->drag_ptC = motion_dt;
4224 by cilix42
Fundamentally reworked version of the 3D box tool (among many other things, this fixes bugs #168900 and #168868). See mailing list for details. Sorry for this single large commit but it was unfeasible to keep the history.
363
9020 by JazzyNico
Code refactoring and merging with trunk (revision 10599).
364
                bc->drag_ptB_proj = cur_persp->perspective_impl->tmat.preimage (motion_dt, 0, Proj::Z);
4224 by cilix42
Fundamentally reworked version of the 3D box tool (among many other things, this fixes bugs #168900 and #168868). See mailing list for details. Sorry for this single large commit but it was unfeasible to keep the history.
365
                bc->drag_ptC_proj = bc->drag_ptB_proj;
366
                bc->drag_ptC_proj.normalize();
367
                bc->drag_ptC_proj[Proj::Z] = 0.25;
3084 by cilix42
First (very limited) version of the 3D box tool; allows for drawing of new boxes in a fixed perspective without any live interaction.
368
            } else {
369
                // Without Ctrl, motion of the extruded corner is constrained to the
370
                // perspective line from drag_ptB to vanishing point Y.
3385 by cilix42
Cosmetic
371
                if (!bc->ctrl_dragged) {
4224 by cilix42
Fundamentally reworked version of the 3D box tool (among many other things, this fixes bugs #168900 and #168868). See mailing list for details. Sorry for this single large commit but it was unfeasible to keep the history.
372
                    /* snapping */
8910 by Maximilian Albert
Refactoring of 3D box tool, mainly to avoid unnecessary creation of perspectives.
373
                    Box3D::PerspectiveLine pline (bc->drag_ptB, Proj::Z, document->getCurrentPersp3D());
9020 by JazzyNico
Code refactoring and merging with trunk (revision 10599).
374
                    bc->drag_ptC = pline.closest_to (motion_dt);
4224 by cilix42
Fundamentally reworked version of the 3D box tool (among many other things, this fixes bugs #168900 and #168868). See mailing list for details. Sorry for this single large commit but it was unfeasible to keep the history.
375
376
                    bc->drag_ptB_proj.normalize();
8910 by Maximilian Albert
Refactoring of 3D box tool, mainly to avoid unnecessary creation of perspectives.
377
                    bc->drag_ptC_proj = cur_persp->perspective_impl->tmat.preimage (bc->drag_ptC, bc->drag_ptB_proj[Proj::X], Proj::X);
3084 by cilix42
First (very limited) version of the 3D box tool; allows for drawing of new boxes in a fixed perspective without any live interaction.
378
                } else {
9020 by JazzyNico
Code refactoring and merging with trunk (revision 10599).
379
                    bc->drag_ptC = motion_dt;
4224 by cilix42
Fundamentally reworked version of the 3D box tool (among many other things, this fixes bugs #168900 and #168868). See mailing list for details. Sorry for this single large commit but it was unfeasible to keep the history.
380
381
                    bc->drag_ptB_proj.normalize();
9020 by JazzyNico
Code refactoring and merging with trunk (revision 10599).
382
                    bc->drag_ptC_proj = cur_persp->perspective_impl->tmat.preimage (motion_dt, bc->drag_ptB_proj[Proj::X], Proj::X);
3084 by cilix42
First (very limited) version of the 3D box tool; allows for drawing of new boxes in a fixed perspective without any live interaction.
383
                }
9012.1.2 by Diederik van Lierop
Remove redundancy from snapping API (type of snapsource no longer has to be specified explicitly)
384
                m.freeSnapReturnByRef(bc->drag_ptC, Inkscape::SNAPSOURCE_NODE_HANDLE);
3084 by cilix42
First (very limited) version of the 3D box tool; allows for drawing of new boxes in a fixed perspective without any live interaction.
385
            }
9020 by JazzyNico
Code refactoring and merging with trunk (revision 10599).
386
            m.unSetup();
4224 by cilix42
Fundamentally reworked version of the 3D box tool (among many other things, this fixes bugs #168900 and #168868). See mailing list for details. Sorry for this single large commit but it was unfeasible to keep the history.
387
388
            sp_box3d_drag(*bc, event->motion.state);
389
3084 by cilix42
First (very limited) version of the 3D box tool; allows for drawing of new boxes in a fixed perspective without any live interaction.
390
            ret = TRUE;
9012.1.47 by Diederik van Lierop
Tiny bit of refactoring (inverting some logic)
391
        } else if (!sp_event_context_knot_mouseover(bc)) {
9012.1.22 by Diederik van Lierop
Finally introducing the pre-snap indicator
392
            SnapManager &m = desktop->namedview->snap_manager;
393
            m.setup(desktop);
394
395
            Geom::Point const motion_w(event->motion.x, event->motion.y);
396
            Geom::Point motion_dt(desktop->w2d(motion_w));
397
            m.preSnap(Inkscape::SnapCandidatePoint(motion_dt, Inkscape::SNAPSOURCE_NODE_HANDLE));
9020 by JazzyNico
Code refactoring and merging with trunk (revision 10599).
398
            m.unSetup();
3084 by cilix42
First (very limited) version of the 3D box tool; allows for drawing of new boxes in a fixed perspective without any live interaction.
399
        }
400
        break;
401
    case GDK_BUTTON_RELEASE:
402
        event_context->xp = event_context->yp = 0;
3341 by buliabyak
due to the order of processing events, we must disable lmb handling in children contexts so that parent event context can handle it for space panning
403
        if ( event->button.button == 1  && !event_context->space_panning) {
3084 by cilix42
First (very limited) version of the 3D box tool; allows for drawing of new boxes in a fixed perspective without any live interaction.
404
            dragging = false;
8302 by dvlierop2
Make the snap delay mechanism easier to implement for the devs, and get rid of the related warning messages
405
            sp_event_context_discard_delayed_snap_event(event_context);
3084 by cilix42
First (very limited) version of the 3D box tool; allows for drawing of new boxes in a fixed perspective without any live interaction.
406
407
            if (!event_context->within_tolerance) {
3209 by cilix42
Status message & cleanups
408
                // we've been dragging, finish the box
4224 by cilix42
Fundamentally reworked version of the 3D box tool (among many other things, this fixes bugs #168900 and #168868). See mailing list for details. Sorry for this single large commit but it was unfeasible to keep the history.
409
                sp_box3d_finish(bc);
3084 by cilix42
First (very limited) version of the 3D box tool; allows for drawing of new boxes in a fixed perspective without any live interaction.
410
            } else if (event_context->item_to_select) {
411
                // no dragging, select clicked item if any
412
                if (event->button.state & GDK_SHIFT_MASK) {
413
                    selection->toggle(event_context->item_to_select);
414
                } else {
415
                    selection->set(event_context->item_to_select);
416
                }
417
            } else {
418
                // click in an empty space
419
                selection->clear();
420
            }
421
422
            event_context->item_to_select = NULL;
423
            ret = TRUE;
424
            sp_canvas_item_ungrab(SP_CANVAS_ITEM(desktop->acetate),
425
                                  event->button.time);
426
        }
427
        break;
428
    case GDK_KEY_PRESS:
429
        switch (get_group0_keyval (&event->key)) {
430
        case GDK_Up:
431
        case GDK_Down:
432
        case GDK_KP_Up:
433
        case GDK_KP_Down:
434
            // prevent the zoom field from activation
435
            if (!MOD__CTRL_ONLY)
436
                ret = TRUE;
437
            break;
438
3657 by cilix42
Infrastructure to set direction of infinite VPs (now adjustable by some shortcuts; this may be removed later on)
439
        case GDK_bracketright:
8910 by Maximilian Albert
Refactoring of 3D box tool, mainly to avoid unnecessary creation of perspectives.
440
            persp3d_rotate_VP (document->getCurrentPersp3D(), Proj::X, -180/snaps, MOD__ALT);
9020 by JazzyNico
Code refactoring and merging with trunk (revision 10599).
441
            DocumentUndo::done(document, SP_VERB_CONTEXT_3DBOX,
4436 by cilix42
Enable 3D box toolbar
442
                             _("Change perspective (angle of PLs)"));
3657 by cilix42
Infrastructure to set direction of infinite VPs (now adjustable by some shortcuts; this may be removed later on)
443
            ret = true;
444
            break;
445
446
        case GDK_bracketleft:
8910 by Maximilian Albert
Refactoring of 3D box tool, mainly to avoid unnecessary creation of perspectives.
447
            persp3d_rotate_VP (document->getCurrentPersp3D(), Proj::X, 180/snaps, MOD__ALT);
9020 by JazzyNico
Code refactoring and merging with trunk (revision 10599).
448
            DocumentUndo::done(document, SP_VERB_CONTEXT_3DBOX,
4436 by cilix42
Enable 3D box toolbar
449
                             _("Change perspective (angle of PLs)"));
3657 by cilix42
Infrastructure to set direction of infinite VPs (now adjustable by some shortcuts; this may be removed later on)
450
            ret = true;
451
            break;
452
453
        case GDK_parenright:
8910 by Maximilian Albert
Refactoring of 3D box tool, mainly to avoid unnecessary creation of perspectives.
454
            persp3d_rotate_VP (document->getCurrentPersp3D(), Proj::Y, -180/snaps, MOD__ALT);
9020 by JazzyNico
Code refactoring and merging with trunk (revision 10599).
455
            DocumentUndo::done(document, SP_VERB_CONTEXT_3DBOX,
4436 by cilix42
Enable 3D box toolbar
456
                             _("Change perspective (angle of PLs)"));
3657 by cilix42
Infrastructure to set direction of infinite VPs (now adjustable by some shortcuts; this may be removed later on)
457
            ret = true;
458
            break;
459
460
        case GDK_parenleft:
8910 by Maximilian Albert
Refactoring of 3D box tool, mainly to avoid unnecessary creation of perspectives.
461
            persp3d_rotate_VP (document->getCurrentPersp3D(), Proj::Y, 180/snaps, MOD__ALT);
9020 by JazzyNico
Code refactoring and merging with trunk (revision 10599).
462
            DocumentUndo::done(document, SP_VERB_CONTEXT_3DBOX,
4436 by cilix42
Enable 3D box toolbar
463
                             _("Change perspective (angle of PLs)"));
3657 by cilix42
Infrastructure to set direction of infinite VPs (now adjustable by some shortcuts; this may be removed later on)
464
            ret = true;
465
            break;
466
467
        case GDK_braceright:
8910 by Maximilian Albert
Refactoring of 3D box tool, mainly to avoid unnecessary creation of perspectives.
468
            persp3d_rotate_VP (document->getCurrentPersp3D(), Proj::Z, -180/snaps, MOD__ALT);
9020 by JazzyNico
Code refactoring and merging with trunk (revision 10599).
469
            DocumentUndo::done(document, SP_VERB_CONTEXT_3DBOX,
4436 by cilix42
Enable 3D box toolbar
470
                             _("Change perspective (angle of PLs)"));
3657 by cilix42
Infrastructure to set direction of infinite VPs (now adjustable by some shortcuts; this may be removed later on)
471
            ret = true;
472
            break;
473
474
        case GDK_braceleft:
8910 by Maximilian Albert
Refactoring of 3D box tool, mainly to avoid unnecessary creation of perspectives.
475
            persp3d_rotate_VP (document->getCurrentPersp3D(), Proj::Z, 180/snaps, MOD__ALT);
9020 by JazzyNico
Code refactoring and merging with trunk (revision 10599).
476
            DocumentUndo::done(document, SP_VERB_CONTEXT_3DBOX,
4436 by cilix42
Enable 3D box toolbar
477
                             _("Change perspective (angle of PLs)"));
4224 by cilix42
Fundamentally reworked version of the 3D box tool (among many other things, this fixes bugs #168900 and #168868). See mailing list for details. Sorry for this single large commit but it was unfeasible to keep the history.
478
            ret = true;
479
            break;
480
8004 by buliabyak
comment out apparently unused code
481
        /* TODO: what is this???
4224 by cilix42
Fundamentally reworked version of the 3D box tool (among many other things, this fixes bugs #168900 and #168868). See mailing list for details. Sorry for this single large commit but it was unfeasible to keep the history.
482
        case GDK_O:
4436 by cilix42
Enable 3D box toolbar
483
            if (MOD__CTRL && MOD__SHIFT) {
8910 by Maximilian Albert
Refactoring of 3D box tool, mainly to avoid unnecessary creation of perspectives.
484
                Box3D::create_canvas_point(persp3d_get_VP(document()->getCurrentPersp3D(), Proj::W).affine(),
4436 by cilix42
Enable 3D box toolbar
485
                                           6, 0xff00ff00);
486
            }
3657 by cilix42
Infrastructure to set direction of infinite VPs (now adjustable by some shortcuts; this may be removed later on)
487
            ret = true;
488
            break;
8004 by buliabyak
comment out apparently unused code
489
        */
3657 by cilix42
Infrastructure to set direction of infinite VPs (now adjustable by some shortcuts; this may be removed later on)
490
4462 by cilix42
Add possibility to convert objects (only rectangles and 3D boxes currently) to guidelines. Also see corresponding post on the mailing list; in particular, feel free to revert it if this is inappropriate during Frost phase.
491
        case GDK_g:
492
        case GDK_G:
493
            if (MOD__SHIFT_ONLY) {
6629 by cilix42
Get rid of a whole bunch of further instances of SP_ACTIVE_DESKTOP (where the desktop is readily available in the calling function)
494
                sp_selection_to_guides(desktop);
4462 by cilix42
Add possibility to convert objects (only rectangles and 3D boxes currently) to guidelines. Also see corresponding post on the mailing list; in particular, feel free to revert it if this is inappropriate during Frost phase.
495
                ret = true;
496
            }
497
            break;
498
8910 by Maximilian Albert
Refactoring of 3D box tool, mainly to avoid unnecessary creation of perspectives.
499
        case GDK_p:
500
        case GDK_P:
501
            if (MOD__SHIFT_ONLY) {
502
                if (document->getCurrentPersp3D()) {
503
                    persp3d_print_debugging_info (document->getCurrentPersp3D());
504
                }
505
                ret = true;
506
            }
507
            break;
508
4224 by cilix42
Fundamentally reworked version of the 3D box tool (among many other things, this fixes bugs #168900 and #168868). See mailing list for details. Sorry for this single large commit but it was unfeasible to keep the history.
509
        case GDK_x:
4465 by cilix42
Better handling of shortcuts in 3D box tool
510
        case GDK_X:
4224 by cilix42
Fundamentally reworked version of the 3D box tool (among many other things, this fixes bugs #168900 and #168868). See mailing list for details. Sorry for this single large commit but it was unfeasible to keep the history.
511
            if (MOD__ALT_ONLY) {
512
                desktop->setToolboxFocusTo ("altx-box3d");
513
                ret = TRUE;
514
            }
4465 by cilix42
Better handling of shortcuts in 3D box tool
515
            if (MOD__SHIFT_ONLY) {
5122 by cilix42
Make grouped 3D boxes work correctly when transformed (fixes: LP 188991)
516
                persp3d_toggle_VPs(selection->perspList(), Proj::X);
4465 by cilix42
Better handling of shortcuts in 3D box tool
517
                bc->_vpdrag->updateLines(); // FIXME: Shouldn't this be done automatically?
518
                ret = true;
519
            }
3393 by cilix42
Draw perspective lines; provide shortcuts to toggle their visibility and the corners where they are attached
520
            break;
4224 by cilix42
Fundamentally reworked version of the 3D box tool (among many other things, this fixes bugs #168900 and #168868). See mailing list for details. Sorry for this single large commit but it was unfeasible to keep the history.
521
4465 by cilix42
Better handling of shortcuts in 3D box tool
522
        case GDK_y:
3393 by cilix42
Draw perspective lines; provide shortcuts to toggle their visibility and the corners where they are attached
523
        case GDK_Y:
4465 by cilix42
Better handling of shortcuts in 3D box tool
524
            if (MOD__SHIFT_ONLY) {
5122 by cilix42
Make grouped 3D boxes work correctly when transformed (fixes: LP 188991)
525
                persp3d_toggle_VPs(selection->perspList(), Proj::Y);
4465 by cilix42
Better handling of shortcuts in 3D box tool
526
                bc->_vpdrag->updateLines(); // FIXME: Shouldn't this be done automatically?
527
                ret = true;
528
            }
3393 by cilix42
Draw perspective lines; provide shortcuts to toggle their visibility and the corners where they are attached
529
            break;
530
4465 by cilix42
Better handling of shortcuts in 3D box tool
531
        case GDK_z:
3393 by cilix42
Draw perspective lines; provide shortcuts to toggle their visibility and the corners where they are attached
532
        case GDK_Z:
4465 by cilix42
Better handling of shortcuts in 3D box tool
533
            if (MOD__SHIFT_ONLY) {
5122 by cilix42
Make grouped 3D boxes work correctly when transformed (fixes: LP 188991)
534
                persp3d_toggle_VPs(selection->perspList(), Proj::Z);
4465 by cilix42
Better handling of shortcuts in 3D box tool
535
                bc->_vpdrag->updateLines(); // FIXME: Shouldn't this be done automatically?
536
                ret = true;
537
            }
3393 by cilix42
Draw perspective lines; provide shortcuts to toggle their visibility and the corners where they are attached
538
            break;
3084 by cilix42
First (very limited) version of the 3D box tool; allows for drawing of new boxes in a fixed perspective without any live interaction.
539
540
        case GDK_Escape:
541
            sp_desktop_selection(desktop)->clear();
542
            //TODO: make dragging escapable by Esc
543
            break;
544
545
        case GDK_space:
546
            if (dragging) {
547
                sp_canvas_item_ungrab(SP_CANVAS_ITEM(desktop->acetate),
548
                                      event->button.time);
549
                dragging = false;
8302 by dvlierop2
Make the snap delay mechanism easier to implement for the devs, and get rid of the related warning messages
550
                sp_event_context_discard_delayed_snap_event(event_context);
3084 by cilix42
First (very limited) version of the 3D box tool; allows for drawing of new boxes in a fixed perspective without any live interaction.
551
                if (!event_context->within_tolerance) {
3209 by cilix42
Status message & cleanups
552
                    // we've been dragging, finish the box
4224 by cilix42
Fundamentally reworked version of the 3D box tool (among many other things, this fixes bugs #168900 and #168868). See mailing list for details. Sorry for this single large commit but it was unfeasible to keep the history.
553
                    sp_box3d_finish(bc);
3084 by cilix42
First (very limited) version of the 3D box tool; allows for drawing of new boxes in a fixed perspective without any live interaction.
554
                }
555
                // do not return true, so that space would work switching to selector
556
            }
557
            break;
558
559
        default:
560
            break;
561
        }
562
        break;
563
    default:
564
        break;
565
    }
566
567
    if (!ret) {
568
        if (((SPEventContextClass *) parent_class)->root_handler) {
569
            ret = ((SPEventContextClass *) parent_class)->root_handler(event_context, event);
570
        }
571
    }
572
573
    return ret;
574
}
575
4234 by joncruz
Warning cleanup
576
static void sp_box3d_drag(Box3DContext &bc, guint /*state*/)
3084 by cilix42
First (very limited) version of the 3D box tool; allows for drawing of new boxes in a fixed perspective without any live interaction.
577
{
9020 by JazzyNico
Code refactoring and merging with trunk (revision 10599).
578
    SPDesktop *desktop = bc.desktop;
3209 by cilix42
Status message & cleanups
579
580
    if (!bc.item) {
581
582
        if (Inkscape::have_viable_layer(desktop, bc._message_context) == false) {
3084 by cilix42
First (very limited) version of the 3D box tool; allows for drawing of new boxes in a fixed perspective without any live interaction.
583
            return;
584
        }
585
9020 by JazzyNico
Code refactoring and merging with trunk (revision 10599).
586
        // Create object
587
        SPBox3D *box3d = 0;
588
        box3d = SPBox3D::createBox3D((SPItem *)desktop->currentLayer());
589
590
        // Set style
591
        desktop->applyCurrentOrToolStyle(box3d, "/tools/shapes/3dbox", false);
592
        
593
        bc.item = box3d;
594
4388 by cilix42
Only set style of box sides during creation (not upon every repr write).
595
        // TODO: Incorporate this in box3d-side.cpp!
3212 by cilix42
Create all 3D box faces in the beginning (fixes resizing bug; first step towards correct handling of degenerate boxes)
596
        for (int i = 0; i < 6; ++i) {
9020 by JazzyNico
Code refactoring and merging with trunk (revision 10599).
597
            Box3DSide *side = Box3DSide::createBox3DSide(box3d);
598
            
4224 by cilix42
Fundamentally reworked version of the 3D box tool (among many other things, this fixes bugs #168900 and #168868). See mailing list for details. Sorry for this single large commit but it was unfeasible to keep the history.
599
            guint desc = Box3D::int_to_face(i);
600
601
            Box3D::Axis plane = (Box3D::Axis) (desc & 0x7);
602
            plane = (Box3D::is_plane(plane) ? plane : Box3D::orth_plane_or_axis(plane));
603
            side->dir1 = Box3D::extract_first_axis_direction(plane);
604
            side->dir2 = Box3D::extract_second_axis_direction(plane);
605
            side->front_or_rear = (Box3D::FrontOrRear) (desc & 0x8);
606
9020 by JazzyNico
Code refactoring and merging with trunk (revision 10599).
607
            // Set style
608
            Inkscape::Preferences *prefs = Inkscape::Preferences::get();
609
610
            Glib::ustring descr = "/desktop/";
611
            descr += box3d_side_axes_string(side);
612
            descr += "/style";
613
            Glib::ustring cur_style = prefs->getString(descr);    
614
    
615
            bool use_current = prefs->getBool("/tools/shapes/3dbox/usecurrent", false);
616
            if (use_current && !cur_style.empty()) {
617
                // use last used style 
618
                side->setAttribute("style", cur_style.data());
619
				
620
            } else {
621
                // use default style 
622
                GString *pstring = g_string_new("");
623
                g_string_printf (pstring, "/tools/shapes/3dbox/%s", box3d_side_axes_string(side));
624
                desktop->applyCurrentOrToolStyle (side, pstring->str, false);
625
            }
626
627
            side->updateRepr(); // calls box3d_side_write() and updates, e.g., the axes string description
3212 by cilix42
Create all 3D box faces in the beginning (fixes resizing bug; first step towards correct handling of degenerate boxes)
628
        }
3084 by cilix42
First (very limited) version of the 3D box tool; allows for drawing of new boxes in a fixed perspective without any live interaction.
629
4224 by cilix42
Fundamentally reworked version of the 3D box tool (among many other things, this fixes bugs #168900 and #168868). See mailing list for details. Sorry for this single large commit but it was unfeasible to keep the history.
630
        box3d_set_z_orders(SP_BOX3D(bc.item));
3209 by cilix42
Status message & cleanups
631
        bc.item->updateRepr();
3409 by cilix42
Set z-orders of 3D box faces during dragging/resizing according to the perspective
632
3391 by cilix42
First stage of draggable vanishing points (no snapping/unsnapping yet)
633
        // TODO: It would be nice to show the VPs during dragging, but since there is no selection
634
        //       at this point (only after finishing the box), we must do this "manually"
8910 by Maximilian Albert
Refactoring of 3D box tool, mainly to avoid unnecessary creation of perspectives.
635
        /* bc._vpdrag->updateDraggers(); */
3084 by cilix42
First (very limited) version of the 3D box tool; allows for drawing of new boxes in a fixed perspective without any live interaction.
636
637
        sp_canvas_force_full_redraw_after_interruptions(desktop->canvas, 5);
638
    }
639
4224 by cilix42
Fundamentally reworked version of the 3D box tool (among many other things, this fixes bugs #168900 and #168868). See mailing list for details. Sorry for this single large commit but it was unfeasible to keep the history.
640
    g_assert(bc.item);
641
642
    SPBox3D *box = SP_BOX3D(bc.item);
643
644
    box->orig_corner0 = bc.drag_origin_proj;
645
    box->orig_corner7 = bc.drag_ptC_proj;
646
4306 by cilix42
Don't show boxes as everted (i.e., always show the same sides) during initial drag, regardless of the mouse pointer position.
647
    box3d_check_for_swapped_coords(box);
648
4224 by cilix42
Fundamentally reworked version of the 3D box tool (among many other things, this fixes bugs #168900 and #168868). See mailing list for details. Sorry for this single large commit but it was unfeasible to keep the history.
649
    /* we need to call this from here (instead of from box3d_position_set(), for example)
650
       because z-order setting must not interfere with display updates during undo/redo */
651
    box3d_set_z_orders (box);
652
4306 by cilix42
Don't show boxes as everted (i.e., always show the same sides) during initial drag, regardless of the mouse pointer position.
653
    box3d_position_set(box);
3084 by cilix42
First (very limited) version of the 3D box tool; allows for drawing of new boxes in a fixed perspective without any live interaction.
654
655
    // status text
3209 by cilix42
Status message & cleanups
656
    bc._message_context->setF(Inkscape::NORMAL_MESSAGE, _("<b>3D Box</b>; with <b>Shift</b> to extrude along the Z axis"));
3084 by cilix42
First (very limited) version of the 3D box tool; allows for drawing of new boxes in a fixed perspective without any live interaction.
657
}
658
4224 by cilix42
Fundamentally reworked version of the 3D box tool (among many other things, this fixes bugs #168900 and #168868). See mailing list for details. Sorry for this single large commit but it was unfeasible to keep the history.
659
static void sp_box3d_finish(Box3DContext *bc)
3084 by cilix42
First (very limited) version of the 3D box tool; allows for drawing of new boxes in a fixed perspective without any live interaction.
660
{
3385 by cilix42
Cosmetic
661
    bc->_message_context->clear();
8587 by buliabyak
fix crash when exiting with 3dbox tool active
662
    bc->ctrl_dragged = false;
663
    bc->extruded = false;
3084 by cilix42
First (very limited) version of the 3D box tool; allows for drawing of new boxes in a fixed perspective without any live interaction.
664
3385 by cilix42
Cosmetic
665
    if ( bc->item != NULL ) {
4224 by cilix42
Fundamentally reworked version of the 3D box tool (among many other things, this fixes bugs #168900 and #168868). See mailing list for details. Sorry for this single large commit but it was unfeasible to keep the history.
666
        SPDesktop * desktop = SP_EVENT_CONTEXT_DESKTOP(bc);
8587 by buliabyak
fix crash when exiting with 3dbox tool active
667
        SPDocument *doc = sp_desktop_document(desktop);
8910 by Maximilian Albert
Refactoring of 3D box tool, mainly to avoid unnecessary creation of perspectives.
668
        if (!doc || !doc->getCurrentPersp3D())
8587 by buliabyak
fix crash when exiting with 3dbox tool active
669
            return;
4224 by cilix42
Fundamentally reworked version of the 3D box tool (among many other things, this fixes bugs #168900 and #168868). See mailing list for details. Sorry for this single large commit but it was unfeasible to keep the history.
670
671
        SPBox3D *box = SP_BOX3D(bc->item);
672
673
        box->orig_corner0 = bc->drag_origin_proj;
674
        box->orig_corner7 = bc->drag_ptC_proj;
675
676
        box->updateRepr();
677
678
        box3d_relabel_corners(box);
3084 by cilix42
First (very limited) version of the 3D box tool; allows for drawing of new boxes in a fixed perspective without any live interaction.
679
680
        sp_canvas_end_forced_full_redraws(desktop->canvas);
681
3385 by cilix42
Cosmetic
682
        sp_desktop_selection(desktop)->set(bc->item);
9020 by JazzyNico
Code refactoring and merging with trunk (revision 10599).
683
        DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_CONTEXT_3DBOX,
3239 by cilix42
Write distinguished corners of 3D boxes to the svg representation from which the box can be recomputed.
684
                         _("Create 3D box"));
3084 by cilix42
First (very limited) version of the 3D box tool; allows for drawing of new boxes in a fixed perspective without any live interaction.
685
3385 by cilix42
Cosmetic
686
        bc->item = NULL;
3084 by cilix42
First (very limited) version of the 3D box tool; allows for drawing of new boxes in a fixed perspective without any live interaction.
687
    }
688
}
689
5008 by cilix42
Move 3D box code out of sp-canvas.cpp
690
void sp_box3d_context_update_lines(SPEventContext *ec) {
691
    /*  update perspective lines if we are in the 3D box tool (so that infinite ones are shown correctly) */
692
    if (SP_IS_BOX3D_CONTEXT (ec)) {
693
        Box3DContext *bc = SP_BOX3D_CONTEXT (ec);
694
        bc->_vpdrag->updateLines();
695
    }
696
}
697
3084 by cilix42
First (very limited) version of the 3D box tool; allows for drawing of new boxes in a fixed perspective without any live interaction.
698
/*
699
  Local Variables:
700
  mode:c++
701
  c-file-style:"stroustrup"
702
  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
703
  indent-tabs-mode:nil
704
  fill-column:99
705
  End:
706
*/
9020 by JazzyNico
Code refactoring and merging with trunk (revision 10599).
707
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :