Code

Warning cleanup.
[inkscape.git] / src / selection-chemistry.cpp
index 0e2fe43d1accc85a66b777de1e268f9b7efce278..dfe47bee842f9b1b08aa2534c919099172723813 100644 (file)
@@ -76,6 +76,7 @@
 #include "helper/units.h"
 #include "sp-item.h"
 #include "box3d.h"
+#include "persp3d.h"
 #include "unit-constants.h"
 #include "xml/simple-document.h"
 #include "sp-filter-reference.h"
@@ -88,9 +89,7 @@
 
 // For clippath editing
 #include "tools-switch.h"
-#include "shape-editor.h"
-#include "node-context.h"
-#include "nodepath.h"
+#include "ui/tool/node-tool.h"
 
 #include "ui/clipboard.h"
 
@@ -139,7 +138,7 @@ void sp_selection_copy_impl(GSList const *items, GSList **clip, Inkscape::XML::D
     g_slist_free((GSList *) sorted_items);
 }
 
-GSList *sp_selection_paste_impl(Document *doc, SPObject *parent, GSList **clip)
+GSList *sp_selection_paste_impl(SPDocument *doc, SPObject *parent, GSList **clip)
 {
     Inkscape::XML::Document *xml_doc = sp_document_repr_doc(doc);
 
@@ -240,7 +239,7 @@ void sp_selection_duplicate(SPDesktop *desktop, bool suppressDone)
     if (desktop == NULL)
         return;
 
-    Document *doc = desktop->doc();
+    SPDocument *doc = desktop->doc();
     Inkscape::XML::Document* xml_doc = sp_document_repr_doc(doc);
     Inkscape::Selection *selection = sp_desktop_selection(desktop);
 
@@ -326,7 +325,7 @@ void sp_edit_clear_all(SPDesktop *dt)
     if (!dt)
         return;
 
-    Document *doc = sp_desktop_document(dt);
+    SPDocument *doc = sp_desktop_document(dt);
     sp_desktop_selection(dt)->clear();
 
     g_return_if_fail(SP_IS_GROUP(dt->currentLayer()));
@@ -454,7 +453,7 @@ void sp_selection_group(SPDesktop *desktop)
     if (desktop == NULL)
         return;
 
-    Document *doc = sp_desktop_document(desktop);
+    SPDocument *doc = sp_desktop_document(desktop);
     Inkscape::XML::Document *xml_doc = sp_document_repr_doc(doc);
 
     Inkscape::Selection *selection = sp_desktop_selection(desktop);
@@ -741,7 +740,7 @@ void sp_selection_raise_to_top(SPDesktop *desktop)
     if (desktop == NULL)
         return;
 
-    Document *document = sp_desktop_document(desktop);
+    SPDocument *document = sp_desktop_document(desktop);
     Inkscape::Selection *selection = sp_desktop_selection(desktop);
 
     if (selection->isEmpty()) {
@@ -839,7 +838,7 @@ void sp_selection_lower_to_bottom(SPDesktop *desktop)
     if (desktop == NULL)
         return;
 
-    Document *document = sp_desktop_document(desktop);
+    SPDocument *document = sp_desktop_document(desktop);
     Inkscape::Selection *selection = sp_desktop_selection(desktop);
 
     if (selection->isEmpty()) {
@@ -882,14 +881,14 @@ void sp_selection_lower_to_bottom(SPDesktop *desktop)
 }
 
 void
-sp_undo(SPDesktop *desktop, Document *)
+sp_undo(SPDesktop *desktop, SPDocument *)
 {
         if (!sp_document_undo(sp_desktop_document(desktop)))
             desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Nothing to undo."));
 }
 
 void
-sp_redo(SPDesktop *desktop, Document *)
+sp_redo(SPDesktop *desktop, SPDocument *)
 {
         if (!sp_document_redo(sp_desktop_document(desktop)))
             desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Nothing to redo."));
@@ -1171,7 +1170,6 @@ selection_contains_both_clone_and_original(Inkscape::Selection *selection)
     return clone_with_original;
 }
 
-
 /** Apply matrix to the selection.  \a set_i2d is normally true, which means objects are in the
 original transform, synced with their reprs, and need to jump to the new transform in one go. A
 value of set_i2d==false is only used by seltrans when it's dragging objects live (not outlines); in
@@ -1183,6 +1181,29 @@ void sp_selection_apply_affine(Inkscape::Selection *selection, Geom::Matrix cons
     if (selection->isEmpty())
         return;
 
+    // For each perspective with a box in selection, check whether all boxes are selected and
+    // unlink all non-selected boxes.
+    Persp3D *persp;
+    Persp3D *transf_persp;
+    std::list<Persp3D *> plist = selection->perspList();
+    for (std::list<Persp3D *>::iterator i = plist.begin(); i != plist.end(); ++i) {
+        persp = (Persp3D *) (*i);
+
+        if (!persp3d_has_all_boxes_in_selection (persp, selection)) {
+            std::list<SPBox3D *> selboxes = selection->box3DList(persp);
+
+            // create a new perspective as a copy of the current one and link the selected boxes to it
+            transf_persp = persp3d_create_xml_element (SP_OBJECT_DOCUMENT(persp), persp->perspective_impl);
+
+            for (std::list<SPBox3D *>::iterator b = selboxes.begin(); b != selboxes.end(); ++b)
+                box3d_switch_perspectives(*b, persp, transf_persp);
+        } else {
+            transf_persp = persp;
+        }
+
+        persp3d_apply_affine_transformation(transf_persp, affine);
+    }
+
     for (GSList const *l = selection->itemList(); l != NULL; l = l->next) {
         SPItem *item = SP_ITEM(l->data);
 
@@ -1672,7 +1693,7 @@ sp_selection_item_next(SPDesktop *desktop)
 void
 sp_selection_item_prev(SPDesktop *desktop)
 {
-    Document *document = sp_desktop_document(desktop);
+    SPDocument *document = sp_desktop_document(desktop);
     g_return_if_fail(document != NULL);
     g_return_if_fail(desktop != NULL);
     Inkscape::Selection *selection = sp_desktop_selection(desktop);
@@ -1716,53 +1737,52 @@ void sp_selection_next_patheffect_param(SPDesktop * dt)
     }
 }
 
-void sp_selection_edit_clip_or_mask(SPDesktop * dt, bool clip)
+/*bool has_path_recursive(SPObject *obj)
 {
-    if (!dt) return;
-
-    Inkscape::Selection *selection = sp_desktop_selection(dt);
-    if ( selection && !selection->isEmpty() ) {
-        SPItem *item = selection->singleItem();
-        if ( item ) {
-            SPObject *obj = NULL;
-            if (clip)
-                obj = item->clip_ref ? SP_OBJECT(item->clip_ref->getObject()) : NULL;
-            else
-                obj = item->mask_ref ? SP_OBJECT(item->mask_ref->getObject()) : NULL;
-
-            if (obj) {
-                // obj is a group object, the children are the actual clippers
-                for ( SPObject *child = obj->children ; child ; child = child->next ) {
-                    if ( SP_IS_ITEM(child) ) {
-                        // If not already in nodecontext, goto it!
-                        if (!tools_isactive(dt, TOOLS_NODES)) {
-                            tools_switch(dt, TOOLS_NODES);
-                        }
-
-                        ShapeEditor * shape_editor = dt->event_context->shape_editor;
-                        // TODO: should we set the item for nodepath or knotholder or both? seems to work with both.
-                        shape_editor->set_item(SP_ITEM(child), SH_NODEPATH);
-                        shape_editor->set_item(SP_ITEM(child), SH_KNOTHOLDER);
-                        Inkscape::NodePath::Path *np = shape_editor->get_nodepath();
-                        if (np) {
-                            // take colors from prefs (same as used in outline mode)
-                            Inkscape::Preferences *prefs = Inkscape::Preferences::get();
-                            np->helperpath_rgba = clip ?
-                                prefs->getInt("/options/wireframecolors/clips", 0x00ff00ff) :
-                                prefs->getInt("/options/wireframecolors/masks", 0x0000ffff);
-                            np->helperpath_width = 1.0;
-                            sp_nodepath_show_helperpath(np, true);
-                        }
-                        break; // break out of for loop after 1st encountered item
-                    }
-                }
-            } else if (clip) {
-                dt->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("The selection has no applied clip path."));
-            } else {
-                dt->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("The selection has no applied mask."));
-            }
+    if (!obj) return false;
+    if (SP_IS_PATH(obj)) {
+        return true;
+    }
+    if (SP_IS_GROUP(obj) || SP_IS_OBJECTGROUP(obj)) {
+        for (SPObject *c = obj->children; c; c = c->next) {
+            if (has_path_recursive(c)) return true;
         }
     }
+    return false;
+}*/
+
+void sp_selection_edit_clip_or_mask(SPDesktop * /*dt*/, bool /*clip*/)
+{
+    return;
+    /*if (!dt) return;
+    using namespace Inkscape::UI;
+
+    Inkscape::Selection *selection = sp_desktop_selection(dt);
+    if (!selection || selection->isEmpty()) return;
+
+    GSList const *items = selection->itemList();
+    bool has_path = false;
+    for (GSList *i = const_cast<GSList*>(items); i; i= i->next) {
+        SPItem *item = SP_ITEM(i->data);
+        SPObject *search = clip
+            ? SP_OBJECT(item->clip_ref ? item->clip_ref->getObject() : NULL)
+            : SP_OBJECT(item->mask_ref ? item->mask_ref->getObject() : NULL);
+        has_path |= has_path_recursive(search);
+        if (has_path) break;
+    }
+    if (has_path) {
+        if (!tools_isactive(dt, TOOLS_NODES)) {
+            tools_switch(dt, TOOLS_NODES);
+        }
+        ink_node_tool_set_mode(INK_NODE_TOOL(dt->event_context),
+            clip ? NODE_TOOL_EDIT_CLIPPING_PATHS : NODE_TOOL_EDIT_MASKS);
+    } else if (clip) {
+        dt->messageStack()->flash(Inkscape::WARNING_MESSAGE,
+            _("The selection has no applied clip path."));
+    } else {
+        dt->messageStack()->flash(Inkscape::WARNING_MESSAGE,
+            _("The selection has no applied mask."));
+    }*/
 }
 
 
@@ -2114,7 +2134,7 @@ void sp_selection_to_marker(SPDesktop *desktop, bool apply)
     if (desktop == NULL)
         return;
 
-    Document *doc = sp_desktop_document(desktop);
+    SPDocument *doc = sp_desktop_document(desktop);
     Inkscape::XML::Document *xml_doc = sp_document_repr_doc(doc);
 
     Inkscape::Selection *selection = sp_desktop_selection(desktop);
@@ -2211,7 +2231,7 @@ void sp_selection_to_guides(SPDesktop *desktop)
     if (desktop == NULL)
         return;
 
-    Document *doc = sp_desktop_document(desktop);
+    SPDocument *doc = sp_desktop_document(desktop);
     Inkscape::Selection *selection = sp_desktop_selection(desktop);
     // we need to copy the list because it gets reset when objects are deleted
     GSList *items = g_slist_copy((GSList *) selection->itemList());
@@ -2238,7 +2258,7 @@ sp_selection_tile(SPDesktop *desktop, bool apply)
     if (desktop == NULL)
         return;
 
-    Document *doc = sp_desktop_document(desktop);
+    SPDocument *doc = sp_desktop_document(desktop);
     Inkscape::XML::Document *xml_doc = sp_document_repr_doc(doc);
 
     Inkscape::Selection *selection = sp_desktop_selection(desktop);
@@ -2342,7 +2362,7 @@ sp_selection_untile(SPDesktop *desktop)
     if (desktop == NULL)
         return;
 
-    Document *doc = sp_desktop_document(desktop);
+    SPDocument *doc = sp_desktop_document(desktop);
     Inkscape::XML::Document *xml_doc = sp_document_repr_doc(doc);
 
     Inkscape::Selection *selection = sp_desktop_selection(desktop);
@@ -2457,7 +2477,7 @@ sp_selection_get_export_hints(Inkscape::Selection *selection, char const **filen
 }
 
 void
-sp_document_get_export_hints(Document *doc, char const **filename, float *xdpi, float *ydpi)
+sp_document_get_export_hints(SPDocument *doc, char const **filename, float *xdpi, float *ydpi)
 {
     Inkscape::XML::Node * repr = sp_document_repr_root(doc);
     gchar const *dpi_string;
@@ -2483,7 +2503,7 @@ sp_selection_create_bitmap_copy(SPDesktop *desktop)
     if (desktop == NULL)
         return;
 
-    Document *document = sp_desktop_document(desktop);
+    SPDocument *document = sp_desktop_document(desktop);
     Inkscape::XML::Document *xml_doc = sp_document_repr_doc(document);
 
     Inkscape::Selection *selection = sp_desktop_selection(desktop);
@@ -2697,7 +2717,7 @@ sp_selection_set_mask(SPDesktop *desktop, bool apply_clip_path, bool apply_to_la
     if (desktop == NULL)
         return;
 
-    Document *doc = sp_desktop_document(desktop);
+    SPDocument *doc = sp_desktop_document(desktop);
     Inkscape::XML::Document *xml_doc = sp_document_repr_doc(doc);
 
     Inkscape::Selection *selection = sp_desktop_selection(desktop);
@@ -2824,7 +2844,7 @@ void sp_selection_unset_mask(SPDesktop *desktop, bool apply_clip_path) {
     if (desktop == NULL)
         return;
 
-    Document *doc = sp_desktop_document(desktop);
+    SPDocument *doc = sp_desktop_document(desktop);
     Inkscape::XML::Document *xml_doc = sp_document_repr_doc(doc);
     Inkscape::Selection *selection = sp_desktop_selection(desktop);
 
@@ -2909,13 +2929,15 @@ void sp_selection_unset_mask(SPDesktop *desktop, bool apply_clip_path) {
 }
 
 /**
- * Returns true if an undoable change should be recorded.
+ * \param with_margins margins defined in the xml under <sodipodi:namedview>
+ *                     "fit-margin-..." attributes.  See SPDocument::fitToRect.
+ * \return true if an undoable change should be recorded.
  */
 bool
-fit_canvas_to_selection(SPDesktop *desktop)
+fit_canvas_to_selection(SPDesktop *desktop, bool with_margins)
 {
     g_return_val_if_fail(desktop != NULL, false);
-    Document *doc = sp_desktop_document(desktop);
+    SPDocument *doc = sp_desktop_document(desktop);
 
     g_return_val_if_fail(doc != NULL, false);
     g_return_val_if_fail(desktop->selection != NULL, false);
@@ -2926,7 +2948,7 @@ fit_canvas_to_selection(SPDesktop *desktop)
     }
     Geom::OptRect const bbox(desktop->selection->bounds());
     if (bbox) {
-        doc->fitToRect(*bbox);
+        doc->fitToRect(*bbox, with_margins);
         return true;
     } else {
         return false;
@@ -2945,8 +2967,12 @@ verb_fit_canvas_to_selection(SPDesktop *const desktop)
     }
 }
 
+/**
+ * \param with_margins margins defined in the xml under <sodipodi:namedview>
+ *                     "fit-margin-..." attributes.  See SPDocument::fitToRect.
+ */
 bool
-fit_canvas_to_drawing(Document *doc)
+fit_canvas_to_drawing(SPDocument *doc, bool with_margins)
 {
     g_return_val_if_fail(doc != NULL, false);
 
@@ -2954,7 +2980,7 @@ fit_canvas_to_drawing(Document *doc)
     SPItem const *const root = SP_ITEM(doc->root);
     Geom::OptRect const bbox(root->getBounds(sp_item_i2d_affine(root)));
     if (bbox) {
-        doc->fitToRect(*bbox);
+        doc->fitToRect(*bbox, with_margins);
         return true;
     } else {
         return false;
@@ -2970,16 +2996,21 @@ verb_fit_canvas_to_drawing(SPDesktop *desktop)
     }
 }
 
+/**
+ * Fits canvas to selection or drawing with margins from <sodipodi:namedview>
+ * "fit-margin-..." attributes.  See SPDocument::fitToRect and
+ * ui/dialog/page-sizer.
+ */
 void fit_canvas_to_selection_or_drawing(SPDesktop *desktop) {
     g_return_if_fail(desktop != NULL);
-    Document *doc = sp_desktop_document(desktop);
+    SPDocument *doc = sp_desktop_document(desktop);
 
     g_return_if_fail(doc != NULL);
     g_return_if_fail(desktop->selection != NULL);
 
     bool const changed = ( desktop->selection->isEmpty()
-                           ? fit_canvas_to_drawing(doc)
-                           : fit_canvas_to_selection(desktop) );
+                           ? fit_canvas_to_drawing(doc, true)
+                           : fit_canvas_to_selection(desktop, true) );
     if (changed) {
         sp_document_done(sp_desktop_document(desktop), SP_VERB_FIT_CANVAS_TO_SELECTION_OR_DRAWING,
                          _("Fit Page to Selection or Drawing"));