Code

Merge and cleanup of GSoC C++-ification project.
[inkscape.git] / src / splivarot.cpp
index b2fe45e19b7668cd4c6d1aeef1428ccb6e65eabd..5f32e591ef906ab4b90c1dfd43a5060f6ef3e594 100644 (file)
@@ -1,4 +1,3 @@
-#define __SP_LIVAROT_C__
 /*
  *  splivarot.cpp
  *  Inkscape
@@ -54,6 +53,8 @@
 
 #include "splivarot.h"
 
+using Inkscape::DocumentUndo;
+
 bool   Ancetre(Inkscape::XML::Node *a, Inkscape::XML::Node *who);
 
 void sp_selected_path_boolop(SPDesktop *desktop, bool_op bop, const unsigned int verb=SP_VERB_NONE, const Glib::ustring description="");
@@ -419,8 +420,8 @@ sp_selected_path_boolop(SPDesktop *desktop, bool_op bop, const unsigned int verb
         {
             SP_OBJECT(l->data)->deleteObject();
         }
-        SPDocumentUndo::done(sp_desktop_document(desktop), SP_VERB_NONE, 
-                         description);
+        DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_NONE, 
+                           description);
         selection->clear();
 
         delete res;
@@ -513,7 +514,7 @@ sp_selected_path_boolop(SPDesktop *desktop, bool_op bop, const unsigned int verb
         for (int i=0;i<nbRP;i++) {
             gchar *d = resPath[i]->svg_dump_path();
 
-            Inkscape::XML::Document *xml_doc = sp_document_repr_doc(desktop->doc());
+            Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc();
             Inkscape::XML::Node *repr = xml_doc->createElement("svg:path");
             repr->setAttribute("style", style);
             if (mask)
@@ -559,7 +560,7 @@ sp_selected_path_boolop(SPDesktop *desktop, bool_op bop, const unsigned int verb
     } else {
         gchar *d = res->svg_dump_path();
 
-        Inkscape::XML::Document *xml_doc = sp_document_repr_doc(desktop->doc());
+        Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc();
         Inkscape::XML::Node *repr = xml_doc->createElement("svg:path");
         repr->setAttribute("style", style);
 
@@ -593,7 +594,7 @@ sp_selected_path_boolop(SPDesktop *desktop, bool_op bop, const unsigned int verb
     if (desc) g_free(desc);
 
     if (verb != SP_VERB_NONE) {
-        SPDocumentUndo::done(sp_desktop_document(desktop), verb, description);
+        DocumentUndo::done(sp_desktop_document(desktop), verb, description);
     }
 
     delete res;
@@ -626,8 +627,7 @@ void sp_selected_path_outline_add_marker( SPObject *marker_object, Geom::Matrix
 
 static
 void item_outline_add_marker( SPObject const *marker_object, Geom::Matrix marker_transform,
-                              Geom::Scale stroke_scale, Geom::Matrix transform,
-                              Geom::PathVector* pathv_in )
+                              Geom::Scale stroke_scale, Geom::PathVector* pathv_in )
 {
     SPMarker* marker = SP_MARKER (marker_object);
     SPItem* marker_item = sp_item_first_item_child(SP_OBJECT(marker_object));
@@ -637,7 +637,7 @@ void item_outline_add_marker( SPObject const *marker_object, Geom::Matrix marker
         tr = stroke_scale * tr;
     }
     // total marker transform
-    tr = marker_item->transform * marker->c2p * tr * transform;
+    tr = marker_item->transform * marker->c2p * tr;
 
     Geom::PathVector* marker_pathv = item_outline(marker_item);
     
@@ -675,6 +675,10 @@ Geom::PathVector* item_outline(SPItem const *item)
         return ret_pathv;
     }
 
+    if (curve->get_pathvector().empty()) {
+        return ret_pathv;
+    }
+
     // remember old stroke style, to be set on fill
     SPStyle *i_style = SP_OBJECT_STYLE(item);
 
@@ -792,7 +796,7 @@ Geom::PathVector* item_outline(SPItem const *item)
                 if ( SPObject *marker_obj = shape->marker[i] ) {
                     Geom::Matrix const m (sp_shape_marker_get_transform_at_start(pathv.front().front()));
                     item_outline_add_marker( marker_obj, m,
-                                             Geom::Scale(i_style->stroke_width.computed), transform,
+                                             Geom::Scale(i_style->stroke_width.computed),
                                              ret_pathv );
                 }
             }
@@ -807,7 +811,7 @@ Geom::PathVector* item_outline(SPItem const *item)
                     {
                         Geom::Matrix const m (sp_shape_marker_get_transform_at_start(path_it->front()));
                         item_outline_add_marker( midmarker_obj, m,
-                                                 Geom::Scale(i_style->stroke_width.computed), transform,
+                                                 Geom::Scale(i_style->stroke_width.computed),
                                                  ret_pathv );
                     }
                     // MID position
@@ -822,7 +826,7 @@ Geom::PathVector* item_outline(SPItem const *item)
                              */
                             Geom::Matrix const m (sp_shape_marker_get_transform(*curve_it1, *curve_it2));
                             item_outline_add_marker( midmarker_obj, m,
-                                                     Geom::Scale(i_style->stroke_width.computed), transform,
+                                                     Geom::Scale(i_style->stroke_width.computed),
                                                      ret_pathv);
 
                             ++curve_it1;
@@ -834,7 +838,7 @@ Geom::PathVector* item_outline(SPItem const *item)
                         Geom::Curve const &lastcurve = path_it->back_default();
                         Geom::Matrix const m = sp_shape_marker_get_transform_at_end(lastcurve);
                         item_outline_add_marker( midmarker_obj, m,
-                                                 Geom::Scale(i_style->stroke_width.computed), transform,
+                                                 Geom::Scale(i_style->stroke_width.computed),
                                                  ret_pathv );
                     }
                 }
@@ -853,7 +857,7 @@ Geom::PathVector* item_outline(SPItem const *item)
 
                     Geom::Matrix const m = sp_shape_marker_get_transform_at_end(lastcurve);
                     item_outline_add_marker( marker_obj, m,
-                                             Geom::Scale(i_style->stroke_width.computed), transform,
+                                             Geom::Scale(i_style->stroke_width.computed),
                                              ret_pathv );
                 }
             }
@@ -901,6 +905,10 @@ sp_selected_path_outline(SPDesktop *desktop)
                 continue;
         }
 
+        if (curve->get_pathvector().empty()) {
+            continue;
+        }
+
         // pas de stroke pas de chocolat
         if (!SP_OBJECT_STYLE(item) || SP_OBJECT_STYLE(item)->stroke.noneSet) {
             curve->unref();
@@ -1058,7 +1066,7 @@ sp_selected_path_outline(SPDesktop *desktop)
         if (res->descr_cmd.size() > 1) { // if there's 0 or 1 node left, drop this path altogether
 
             SPDocument * doc = sp_desktop_document(desktop);
-            Inkscape::XML::Document *xml_doc = sp_document_repr_doc(doc);
+            Inkscape::XML::Document *xml_doc = doc->getReprDoc();
             Inkscape::XML::Node *repr = xml_doc->createElement("svg:path");
 
             // restore old style, but set old stroke style on fill
@@ -1077,7 +1085,7 @@ sp_selected_path_outline(SPDesktop *desktop)
 
             if (SP_IS_SHAPE(item) && SP_SHAPE(item)->hasMarkers ()) {
 
-                Inkscape::XML::Document *xml_doc = sp_document_repr_doc(doc);
+                Inkscape::XML::Document *xml_doc = doc->getReprDoc();
                 Inkscape::XML::Node *g_repr = xml_doc->createElement("svg:g");
 
                 // add the group to the parent
@@ -1216,8 +1224,8 @@ sp_selected_path_outline(SPDesktop *desktop)
     }
 
     if (did) {
-        SPDocumentUndo::done(sp_desktop_document(desktop), SP_VERB_SELECTION_OUTLINE, 
-                         _("Convert stroke to path"));
+        DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_SELECTION_OUTLINE, 
+                           _("Convert stroke to path"));
     } else {
         // TRANSLATORS: "to outline" means "to convert stroke to path"
         desktop->messageStack()->flash(Inkscape::ERROR_MESSAGE, _("<b>No stroked paths</b> in the selection."));
@@ -1420,11 +1428,11 @@ sp_selected_path_create_offset_object(SPDesktop *desktop, int expand, bool updat
     {
         // pas vraiment de points sur le resultat
         // donc il ne reste rien
-        SPDocumentUndo::done(sp_desktop_document(desktop), 
-                         (updating ? SP_VERB_SELECTION_LINKED_OFFSET 
-                          : SP_VERB_SELECTION_DYNAMIC_OFFSET),
-                         (updating ? _("Create linked offset")
-                          : _("Create dynamic offset")));
+        DocumentUndo::done(sp_desktop_document(desktop), 
+                           (updating ? SP_VERB_SELECTION_LINKED_OFFSET 
+                            : SP_VERB_SELECTION_DYNAMIC_OFFSET),
+                           (updating ? _("Create linked offset")
+                            : _("Create dynamic offset")));
         selection->clear();
 
         delete res;
@@ -1438,7 +1446,7 @@ sp_selected_path_create_offset_object(SPDesktop *desktop, int expand, bool updat
 
         tstr[79] = '\0';
 
-        Inkscape::XML::Document *xml_doc = sp_document_repr_doc(desktop->doc());
+        Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc();
         repr = xml_doc->createElement("svg:path");
         repr->setAttribute("sodipodi:type", "inkscape:offset");
         sp_repr_set_svg_double(repr, "inkscape:radius", ( expand > 0
@@ -1491,11 +1499,11 @@ sp_selected_path_create_offset_object(SPDesktop *desktop, int expand, bool updat
         selection->set(nitem);
     }
 
-    SPDocumentUndo::done(sp_desktop_document(desktop), 
-                     (updating ? SP_VERB_SELECTION_LINKED_OFFSET 
-                      : SP_VERB_SELECTION_DYNAMIC_OFFSET),
-                     (updating ? _("Create linked offset")
-                      : _("Create dynamic offset")));
+    DocumentUndo::done(sp_desktop_document(desktop), 
+                       (updating ? SP_VERB_SELECTION_LINKED_OFFSET 
+                        : SP_VERB_SELECTION_DYNAMIC_OFFSET),
+                       (updating ? _("Create linked offset")
+                        : _("Create dynamic offset")));
 
     delete res;
     delete orig;
@@ -1704,7 +1712,7 @@ sp_selected_path_do_offset(SPDesktop *desktop, bool expand, double prefOffset)
 
             tstr[79] = '\0';
 
-            Inkscape::XML::Document *xml_doc = sp_document_repr_doc(desktop->doc());
+            Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc();
             Inkscape::XML::Node *repr = xml_doc->createElement("svg:path");
 
             repr->setAttribute("style", style);
@@ -1736,9 +1744,9 @@ sp_selected_path_do_offset(SPDesktop *desktop, bool expand, double prefOffset)
     }
 
     if (did) {
-        SPDocumentUndo::done(sp_desktop_document(desktop), 
-                         (expand ? SP_VERB_SELECTION_OFFSET : SP_VERB_SELECTION_INSET),
-                         (expand ? _("Outset path") : _("Inset path")));
+        DocumentUndo::done(sp_desktop_document(desktop), 
+                           (expand ? SP_VERB_SELECTION_OFFSET : SP_VERB_SELECTION_INSET),
+                           (expand ? _("Outset path") : _("Inset path")));
     } else {
         desktop->messageStack()->flash(Inkscape::ERROR_MESSAGE, _("<b>No paths</b> to inset/outset in the selection."));
         return;
@@ -1841,7 +1849,7 @@ sp_selected_path_simplify_item(SPDesktop *desktop,
         orig->Simplify(threshold * size);
     }
 
-    Inkscape::XML::Document *xml_doc = sp_document_repr_doc(desktop->doc());
+    Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc();
     Inkscape::XML::Node *repr = xml_doc->createElement("svg:path");
 
     // restore style, mask and clip-path
@@ -1996,8 +2004,8 @@ sp_selected_path_simplify_selection(SPDesktop *desktop, float threshold, bool ju
                                                         breakableAngles, true);
 
     if (didSomething)
-        SPDocumentUndo::done(sp_desktop_document(desktop), SP_VERB_SELECTION_SIMPLIFY, 
-                         _("Simplify"));
+        DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_SELECTION_SIMPLIFY, 
+                           _("Simplify"));
     else
         desktop->messageStack()->flash(Inkscape::ERROR_MESSAGE, _("<b>No paths</b> to simplify in the selection."));
 
@@ -2151,4 +2159,4 @@ Geom::Point get_point_on_Path(Path *path, int piece, double t)
   fill-column:99
   End:
 */
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :