Code

Changed preference to use file chooser button
[inkscape.git] / src / selection.cpp
index 201661eecc89345575aede6f4195c8ce66ef1efb..af5db825c0c19efc905bfef8a4559a298fa10da9 100644 (file)
@@ -27,6 +27,8 @@
 #include "xml/repr.h"
 
 #include "sp-shape.h"
+#include "sp-path.h"
+#include "sp-item-group.h"
 
 #include <sigc++/functors/mem_fun.h>
 
@@ -303,25 +305,25 @@ Inkscape::XML::Node *Selection::singleRepr() {
     return obj ? SP_OBJECT_REPR(obj) : NULL;
 }
 
-NRRect *Selection::bounds(NRRect *bbox) const
+NRRect *Selection::bounds(NRRect *bbox, SPItem::BBoxType type) const
 {
     g_return_val_if_fail (bbox != NULL, NULL);
-    *bbox = NRRect(bounds());
+    *bbox = NRRect(bounds(type));
     return bbox;
 }
 
-NR::Maybe<NR::Rect> Selection::bounds() const
+NR::Maybe<NR::Rect> Selection::bounds(SPItem::BBoxType type) const
 {
     GSList const *items = const_cast<Selection *>(this)->itemList();
 
     NR::Maybe<NR::Rect> bbox = NR::Nothing();
     for ( GSList const *i = items ; i != NULL ; i = i->next ) {
-        bbox = NR::union_bounds(bbox, sp_item_bbox_desktop(SP_ITEM(i->data)));
+        bbox = NR::union_bounds(bbox, sp_item_bbox_desktop(SP_ITEM(i->data), type));
     }
     return bbox;
 }
 
-NRRect *Selection::boundsInDocument(NRRect *bbox) const {
+NRRect *Selection::boundsInDocument(NRRect *bbox, SPItem::BBoxType type) const {
     g_return_val_if_fail (bbox != NULL, NULL);
 
     GSList const *items=const_cast<Selection *>(this)->itemList();
@@ -335,16 +337,16 @@ NRRect *Selection::boundsInDocument(NRRect *bbox) const {
 
     for ( GSList const *iter=items ; iter != NULL ; iter = iter->next ) {
         SPItem *item=SP_ITEM(iter->data);
-        NR::Matrix const i2doc(sp_item_i2doc_affine(item));
-        sp_item_invoke_bbox(item, bbox, i2doc, FALSE);
+        NR::Matrix i2doc(sp_item_i2doc_affine(item));
+        sp_item_invoke_bbox(item, bbox, i2doc, FALSE, type);
     }
 
     return bbox;
 }
 
-NR::Maybe<NR::Rect> Selection::boundsInDocument() const {
+NR::Maybe<NR::Rect> Selection::boundsInDocument(SPItem::BBoxType type) const {
     NRRect r;
-    return boundsInDocument(&r)->upgrade();
+    return boundsInDocument(&r, type)->upgrade();
 }
 
 /** Extract the position of the center from the first selected object */
@@ -367,12 +369,25 @@ NR::Maybe<NR::Point> Selection::center() const {
 
 /**
  * Compute the list of points in the selection that are to be considered for snapping.
+ * This includes all special points of each item in the selection, except path nodes
  */
-std::vector<NR::Point> Selection::getSnapPoints() const {
+std::vector<NR::Point> Selection::getSnapPoints(bool includeItemCenter) const {
     GSList const *items = const_cast<Selection *>(this)->itemList();
     std::vector<NR::Point> p;
     for (GSList const *iter = items; iter != NULL; iter = iter->next) {
-        sp_item_snappoints(SP_ITEM(iter->data), SnapPointsIter(p));
+        // getSnapPoints() is only being used in the selector tool, which should
+        // not snap path nodes. Only the node tool should snap those.
+        SPItem *this_item = SP_ITEM(iter->data);
+        if (!SP_IS_PATH(this_item)) {
+            // Only snap if we don't have a path at hand
+            // (Same check occurs in sp-item-group)
+            sp_item_snappoints(this_item, false, SnapPointsIter(p));
+        }
+        //Include the transformation origin for snapping
+        //For a group only the group's origin is considered
+        if (includeItemCenter) {
+               p.push_back(this_item->getCenter());
+        }  
     }
 
     return p;
@@ -383,7 +398,7 @@ std::vector<NR::Point> Selection::getSnapPointsConvexHull() const {
 
     std::vector<NR::Point> p;
     for (GSList const *iter = items; iter != NULL; iter = iter->next) {
-       sp_item_snappoints(SP_ITEM(iter->data), SnapPointsIter(p));
+               sp_item_snappoints(SP_ITEM(iter->data), false, SnapPointsIter(p));
     }
 
     std::vector<NR::Point> pHull;