From 307028df56a44d307292d92f319456ad88d6081f Mon Sep 17 00:00:00 2001 From: cilix42 Date: Tue, 15 Jan 2008 22:09:09 +0000 Subject: [PATCH] Slightly more 'object-oriented' way to invoke item-specific conversion-to-guides methods --- src/box3d.cpp | 14 ++++++-------- src/box3d.h | 1 - src/selection-chemistry.cpp | 9 ++------- src/sp-item.cpp | 16 ++++++++++++++++ src/sp-item.h | 5 +++++ src/sp-rect.cpp | 10 +++++----- src/sp-rect.h | 2 -- 7 files changed, 34 insertions(+), 23 deletions(-) diff --git a/src/box3d.cpp b/src/box3d.cpp index f28dc8f26..4aca24c42 100644 --- a/src/box3d.cpp +++ b/src/box3d.cpp @@ -50,6 +50,7 @@ static Inkscape::XML::Node *box3d_write(SPObject *object, Inkscape::XML::Node *r static gchar *box3d_description(SPItem *item); static NR::Matrix box3d_set_transform(SPItem *item, NR::Matrix const &xform); +static void box3d_convert_to_guides(SPItem *item); static void box3d_ref_changed(SPObject *old_ref, SPObject *ref, SPBox3D *box); static void box3d_ref_modified(SPObject *href, guint flags, SPBox3D *box); @@ -98,6 +99,7 @@ box3d_class_init(SPBox3DClass *klass) item_class->description = box3d_description; item_class->set_transform = box3d_set_transform; + item_class->convert_to_guides = box3d_convert_to_guides; } static void @@ -1491,22 +1493,22 @@ box3d_convert_to_group(SPBox3D *box) { return SP_GROUP(doc->getObjectByRepr(grepr)); } -static void +static inline void box3d_push_back_corner_pair(SPBox3D *box, std::list > &pts, int c1, int c2) { pts.push_back(std::make_pair(box3d_get_corner_screen(box, c1).to_2geom(), box3d_get_corner_screen(box, c2).to_2geom())); } void -box3d_convert_to_guides(SPBox3D *box, bool write_undo) { +box3d_convert_to_guides(SPItem *item) { + SPBox3D *box = SP_BOX3D(item); + if (prefs_get_int_attribute("tools.shapes.3dbox", "convertguides", 1) == 0) { sp_item_convert_to_guides(SP_ITEM(box)); return; } SPDocument *doc = SP_OBJECT_DOCUMENT(box); - //SPDesktop *desktop = inkscape_active_desktop(); - //Inkscape::XML::Document *xml_doc = sp_document_repr_doc(doc); std::list > pts; @@ -1531,10 +1533,6 @@ box3d_convert_to_guides(SPBox3D *box, bool write_undo) { sp_guide_pt_pairs_to_guides(doc, pts); SP_OBJECT(box)->deleteObject(true); - - if (write_undo) { - sp_document_done(doc, SP_VERB_CONTEXT_3DBOX, _("Convert to guides")); - } } /* diff --git a/src/box3d.h b/src/box3d.h index bcbd975c5..fae3849d8 100644 --- a/src/box3d.h +++ b/src/box3d.h @@ -82,7 +82,6 @@ Persp3D *box3d_get_perspective(SPBox3D const *box); void box3d_switch_perspectives(SPBox3D *box, Persp3D *old_persp, Persp3D *new_persp, bool recompute_corners = false); SPGroup *box3d_convert_to_group(SPBox3D *box); -void box3d_convert_to_guides(SPBox3D *box, bool write_undo = true); #endif /* __SP_BOX3D_H__ */ diff --git a/src/selection-chemistry.cpp b/src/selection-chemistry.cpp index b1a579d8b..4cf34e2c5 100644 --- a/src/selection-chemistry.cpp +++ b/src/selection-chemistry.cpp @@ -79,7 +79,6 @@ #include "gradient-drag.h" #include "uri-references.h" #include "live_effects/lpeobject.h" -#include "sp-rect.h" using NR::X; using NR::Y; @@ -2443,16 +2442,12 @@ void sp_selection_to_marker(bool apply) } static void sp_selection_to_guides_recursive(SPItem *item) { - if (SP_IS_RECT(item)) { - sp_rect_convert_to_guides(SP_RECT(item), false); - } else if (SP_IS_BOX3D(item)) { - box3d_convert_to_guides(SP_BOX3D(item), false); - } else if (SP_IS_GROUP(item)) { + if (SP_IS_GROUP(item) && !SP_IS_BOX3D(item)) { for (GSList *i = sp_item_group_item_list (SP_GROUP(item)); i != NULL; i = i->next) { sp_selection_to_guides_recursive(SP_ITEM(i->data)); } } else { - sp_item_convert_to_guides(item); + sp_item_convert_item_to_guides(item); } } diff --git a/src/sp-item.cpp b/src/sp-item.cpp index 7b3687607..078ff6c59 100644 --- a/src/sp-item.cpp +++ b/src/sp-item.cpp @@ -1368,6 +1368,22 @@ sp_item_set_item_transform(SPItem *item, NR::Matrix const &transform) } } +void +sp_item_convert_item_to_guides(SPItem *item) { + g_return_if_fail(item != NULL); + g_return_if_fail(SP_IS_ITEM(item)); + + /* Use derived method if present ... */ + if (((SPItemClass *) G_OBJECT_GET_CLASS(item))->convert_to_guides) { + (*((SPItemClass *) G_OBJECT_GET_CLASS(item))->convert_to_guides)(item); + return; + } + + /* .. otherwise simply place the guides around the item's bounding box */ + + sp_item_convert_to_guides(item); +} + /** * \pre \a ancestor really is an ancestor (\>=) of \a object, or NULL. diff --git a/src/sp-item.h b/src/sp-item.h index 8816bd387..18a3c2df7 100644 --- a/src/sp-item.h +++ b/src/sp-item.h @@ -197,6 +197,9 @@ struct SPItemClass { /** Apply the transform optimally, and return any residual transformation */ NR::Matrix (* set_transform)(SPItem *item, NR::Matrix const &transform); + + /** Convert the item to guidelines */ + void (* convert_to_guides)(SPItem *item); /** Emit event, if applicable */ gint (* event) (SPItem *item, SPEvent *event); @@ -237,6 +240,8 @@ void sp_item_write_transform(SPItem *item, Inkscape::XML::Node *repr, NR::Matrix void sp_item_set_item_transform(SPItem *item, NR::Matrix const &transform); +void sp_item_convert_item_to_guides(SPItem *item); + gint sp_item_event (SPItem *item, SPEvent *event); /* Utility */ diff --git a/src/sp-rect.cpp b/src/sp-rect.cpp index 5770e623d..a26d41599 100644 --- a/src/sp-rect.cpp +++ b/src/sp-rect.cpp @@ -43,6 +43,7 @@ static Inkscape::XML::Node *sp_rect_write(SPObject *object, Inkscape::XML::Node static gchar *sp_rect_description(SPItem *item); static NR::Matrix sp_rect_set_transform(SPItem *item, NR::Matrix const &xform); +static void sp_rect_convert_to_guides(SPItem *item); static void sp_rect_set_shape(SPShape *shape); static void sp_rect_snappoints(SPItem const *item, SnapPointsIter p); @@ -88,6 +89,7 @@ sp_rect_class_init(SPRectClass *klass) item_class->description = sp_rect_description; item_class->set_transform = sp_rect_set_transform; + item_class->convert_to_guides = sp_rect_convert_to_guides; item_class->snappoints = sp_rect_snappoints; //override the default sp_shape_snappoints; see sp_rect_snappoints for details shape_class->set_shape = sp_rect_set_shape; @@ -581,7 +583,9 @@ static void sp_rect_snappoints(SPItem const *item, SnapPointsIter p) } void -sp_rect_convert_to_guides(SPRect *rect, bool write_undo) { +sp_rect_convert_to_guides(SPItem *item) { + SPRect *rect = SP_RECT(item); + if (prefs_get_int_attribute("tools.shapes.rect", "convertguides", 1) == 0) { sp_item_convert_to_guides(SP_ITEM(rect)); return; @@ -605,10 +609,6 @@ sp_rect_convert_to_guides(SPRect *rect, bool write_undo) { sp_guide_pt_pairs_to_guides(doc, pts); SP_OBJECT(rect)->deleteObject(true); - - if (write_undo) { - sp_document_done(doc, SP_VERB_CONTEXT_RECT, _("Convert to guides")); - } } /* diff --git a/src/sp-rect.h b/src/sp-rect.h index 0133922e8..4cf3b24ba 100644 --- a/src/sp-rect.h +++ b/src/sp-rect.h @@ -62,6 +62,4 @@ gdouble sp_rect_get_visible_height (SPRect *rect); void sp_rect_compensate_rxry (SPRect *rect, NR::Matrix xform); -void sp_rect_convert_to_guides(SPRect *rect, bool write_undo = true); - #endif -- 2.30.2