From 7985c9edf0662afa7802203e6277d89673789a39 Mon Sep 17 00:00:00 2001 From: cilix42 Date: Sat, 14 Jul 2007 16:46:20 +0000 Subject: [PATCH] Move check for unlinked paths of 3D box faces to the correct location --- src/box3d-context.cpp | 8 -------- src/box3d.cpp | 36 ++++++++++++++++++++++++------------ 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/src/box3d-context.cpp b/src/box3d-context.cpp index 0bcf9ffa4..ada272acd 100644 --- a/src/box3d-context.cpp +++ b/src/box3d-context.cpp @@ -203,14 +203,6 @@ void sp_3dbox_context_selection_changed(Inkscape::Selection *selection, gpointer ec->shape_repr = shape_repr; Inkscape::GC::anchor(shape_repr); sp_repr_add_listener(shape_repr, &ec_shape_repr_events, ec); - - // FIXME: The following really belongs in sp_3dbox_build. But when undoing & redoing the - // creation of a 3D box, we have no means of accessing the recreated paths, which - // seem to be built after the box itself. Thus we need to check for untracked paths - // here and hook them to the box if the latter was created by a redo operation. - if (SP_IS_3DBOX(item)) { - sp_3dbox_link_to_existing_paths (SP_3DBOX(item), shape_repr); - } } } } diff --git a/src/box3d.cpp b/src/box3d.cpp index 101cce565..eb67269ce 100644 --- a/src/box3d.cpp +++ b/src/box3d.cpp @@ -33,6 +33,7 @@ static gchar *sp_3dbox_description(SPItem *item); //static void sp_3dbox_set_shape(SPShape *shape); static void sp_3dbox_set_shape(SP3DBox *box3d); +static void sp_3dbox_update_corner_with_value_from_svg (SPObject *object, guint corner_id, const gchar *value); static gchar * sp_3dbox_get_corner_coords_string (SP3DBox *box, guint id); static std::pair sp_3dbox_get_coord_pair_from_string (const gchar *); @@ -142,18 +143,6 @@ sp_3dbox_release (SPObject *object) } */ -static void -sp_3dbox_update_corner_with_value_from_svg (SPObject *object, guint corner_id, const gchar *value) -{ - if (value == NULL) return; - SP3DBox *box = SP_3DBOX(object); - - std::pair coord_pair = sp_3dbox_get_coord_pair_from_string (value); - box->corners[corner_id] = NR::Point (coord_pair.first, coord_pair.second); - sp_3dbox_recompute_corners (box, box->corners[2], box->corners[1], box->corners[5]); - object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); -} - static void sp_3dbox_set(SPObject *object, unsigned int key, const gchar *value) { switch (key) { @@ -177,6 +166,11 @@ static void sp_3dbox_set(SPObject *object, unsigned int key, const gchar *value) static void sp_3dbox_update(SPObject *object, SPCtx *ctx, guint flags) { + if (flags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG)) { + SP3DBox *box = SP_3DBOX(object); + sp_3dbox_link_to_existing_paths (box, SP_OBJECT_REPR(object)); + } + /* Invoke parent method */ if (((SPObjectClass *) (parent_class))->update) ((SPObjectClass *) (parent_class))->update(object, ctx, flags); @@ -299,6 +293,11 @@ sp_3dbox_update_curves (SP3DBox *box) { } } +/** + * In some situations (e.g., after cloning boxes, undo & redo, or reading boxes from a file) there are + * paths already present in the document which correspond to the faces of newly created boxes, but their + * 'path' members don't link to them yet. The following function corrects this if necessary. + */ void sp_3dbox_link_to_existing_paths (SP3DBox *box, Inkscape::XML::Node *repr) { // TODO: We should probably destroy the existing paths and recreate them because we don't know @@ -445,6 +444,19 @@ sp_3dbox_get_coord_pair_from_string (const gchar *coords) return std::make_pair(coord1, coord2); } +// auxiliary function +static void +sp_3dbox_update_corner_with_value_from_svg (SPObject *object, guint corner_id, const gchar *value) +{ + if (value == NULL) return; + SP3DBox *box = SP_3DBOX(object); + + std::pair coord_pair = sp_3dbox_get_coord_pair_from_string (value); + box->corners[corner_id] = NR::Point (coord_pair.first, coord_pair.second); + sp_3dbox_recompute_corners (box, box->corners[2], box->corners[1], box->corners[5]); + object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); +} + /* Local Variables: mode:c++ -- 2.30.2