Code

fix converting 3d boxes to path and ungrouping - do not lose selection, preserve...
authorbuliabyak <buliabyak@users.sourceforge.net>
Mon, 25 Feb 2008 10:11:26 +0000 (10:11 +0000)
committerbuliabyak <buliabyak@users.sourceforge.net>
Mon, 25 Feb 2008 10:11:26 +0000 (10:11 +0000)
src/box3d.cpp
src/box3d.h
src/path-chemistry.cpp
src/sp-item-group.cpp

index 7f52abd8cbc65f666fc0efe3847897a1746f1f9b..5beee4accab9e3fb439ddb846bdadb88c99ea5fd 100644 (file)
@@ -1336,8 +1336,7 @@ box3d_switch_perspectives(SPBox3D *box, Persp3D *old_persp, Persp3D *new_persp,
 
 /* Converts the 3D box to an ordinary SPGroup, adds it to the XML tree at the same position as
    the original box and deletes the latter */
-// TODO: Copy over all important attributes (see sp_selected_item_to_curved_repr() for an example)
-SPGroup *
+Inkscape::XML::Node *
 box3d_convert_to_group(SPBox3D *box) {
     SPDocument *doc = SP_OBJECT_DOCUMENT(box);
     Inkscape::XML::Document *xml_doc = sp_document_repr_doc(doc);
@@ -1345,6 +1344,13 @@ box3d_convert_to_group(SPBox3D *box) {
     // remember position of the box
     int pos = SP_OBJECT_REPR(box)->position();
 
+    // remember important attributes
+    Inkscape::XML::Node *repr_source = SP_OBJECT_REPR(box);
+    gchar const *id = repr_source->attribute("id");
+    gchar const *style = repr_source->attribute("style");
+    gchar const *mask = repr_source->attribute("mask");
+    gchar const *clip_path = repr_source->attribute("clip-path");
+
     // create a new group and add the sides (converted to ordinary paths) as its children
     Inkscape::XML::Node *grepr = xml_doc->createElement("svg:g");
 
@@ -1354,7 +1360,7 @@ box3d_convert_to_group(SPBox3D *box) {
             repr = box3d_side_convert_to_path(SP_BOX3D_SIDE(child));
             grepr->appendChild(repr);
         } else {
-            g_warning("Non-side item encountered as child of a 3D box.\n");
+            g_warning("Non-side item encountered as child of a 3D box.");
         }
     }
 
@@ -1362,10 +1368,17 @@ box3d_convert_to_group(SPBox3D *box) {
     SPObject *parent = SP_OBJECT_PARENT(box);
     SP_OBJECT_REPR(parent)->appendChild(grepr);
     grepr->setPosition(pos);
+    grepr->setAttribute("style", style);
+    if (mask)
+       grepr->setAttribute("mask", mask);
+    if (clip_path)
+       grepr->setAttribute("clip-path", clip_path);
 
     SP_OBJECT(box)->deleteObject(true);
 
-    return SP_GROUP(doc->getObjectByRepr(grepr));
+    grepr->setAttribute("id", id);
+
+    return grepr;
 }
 
 static inline void
index 2fbf224a5ea57e17ba290b0c56488557ff70b328..d9fd540b68d9217087a11b6c89678f44a9032fb6 100644 (file)
@@ -77,7 +77,7 @@ void box3d_mark_transformed(SPBox3D *box);
 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);
+Inkscape::XML::Node *box3d_convert_to_group(SPBox3D *box);
 
 
 #endif /* __SP_BOX3D_H__ */
index 254a00e275fa5f0b27f86534ebd31b443794ca02..7466a706626b7e7df57141cfc6f7a0658d2a1ecb 100644 (file)
@@ -297,12 +297,13 @@ sp_selected_path_to_curves0(gboolean interactive, guint32 /*text_grouping_policy
 
         if (SP_IS_BOX3D(item)) {
             // convert 3D box to ordinary group of paths; replace the old element in 'selected' with the new group
-            GSList *sel_it = g_slist_find(selected, item);
-            sel_it->data = box3d_convert_to_group(SP_BOX3D(item));
-            item = SP_ITEM(sel_it->data);
-
-            did = true;
-            selected = g_slist_remove (selected, item);
+            Inkscape::XML::Node *repr = box3d_convert_to_group(SP_BOX3D(item));
+            
+            if (repr) {
+                to_select = g_slist_prepend (to_select, repr);
+                did = true;
+                selected = g_slist_remove (selected, item);
+            }
 
             continue;
         }
index ac7aee1d4f1ea38f0f176f7a0651faaed1a79155..5ae5713ca429fcac4a87b29ba05b02fc77ca38bf 100644 (file)
@@ -329,11 +329,13 @@ sp_item_group_ungroup (SPGroup *group, GSList **children, bool do_done)
        SPItem *pitem = SP_ITEM (SP_OBJECT_PARENT (gitem));
        Inkscape::XML::Node *prepr = SP_OBJECT_REPR (pitem);
 
-        if (SP_IS_BOX3D(gitem)) {
-            group = box3d_convert_to_group(SP_BOX3D(gitem));
-            gitem = SP_ITEM(group);
-            grepr = SP_OBJECT_REPR(gitem);
-        }
+  if (SP_IS_BOX3D(gitem)) {
+      grepr = box3d_convert_to_group(SP_BOX3D(gitem));
+      if (grepr) {
+          gitem = SP_ITEM(doc->getObjectByRepr(grepr));
+          group = SP_GROUP(gitem);
+      }
+  }
 
        /* Step 1 - generate lists of children objects */
        GSList *items = NULL;