Code

Slightly more 'object-oriented' way to invoke item-specific conversion-to-guides...
authorcilix42 <cilix42@users.sourceforge.net>
Tue, 15 Jan 2008 22:09:09 +0000 (22:09 +0000)
committercilix42 <cilix42@users.sourceforge.net>
Tue, 15 Jan 2008 22:09:09 +0000 (22:09 +0000)
src/box3d.cpp
src/box3d.h
src/selection-chemistry.cpp
src/sp-item.cpp
src/sp-item.h
src/sp-rect.cpp
src/sp-rect.h

index f28dc8f262726dfd539dbccd5c02b2f11a3793a5..4aca24c4260add33cda3e4d6c69508cabac91b9a 100644 (file)
@@ -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<std::pair<Geom::Point, Geom::Point> > &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<std::pair<Geom::Point, Geom::Point> > 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"));
-    }
 }
 
 /*
index bcbd975c5a961288f3661780a633e78e98d4c793..fae3849d82266ff276cd522fd897a05ba84a049d 100644 (file)
@@ -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__ */
index b1a579d8b316b766301ef28fe2cffda900b6ee42..4cf34e2c565e8f84297ae574995e3797486486b2 100644 (file)
@@ -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);
     }
 }
 
index 7b3687607d7fb3abe1806b76a1747a608c009099..078ff6c5948fffc1d573e1bd61b4850a233b916d 100644 (file)
@@ -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.
index 8816bd3874e4e1df35a2c2b7adbd603fdcd1de43..18a3c2df74f144107fc140114aa9578f4932b884 100644 (file)
@@ -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 */
index 5770e623d753f6a8f1e12318b4c90aaf7a81187d..a26d415995d92911e917bc50f3fe2e583dac86b8 100644 (file)
@@ -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"));
-    }
 }
 
 /*
index 0133922e8a84e3ebce0a3f5552d6524629df23aa..4cf3b24ba07994d03559e3cd5f56251fc72c0284 100644 (file)
@@ -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