Code

fix leak of the arena and arenaitem
[inkscape.git] / src / seltrans.cpp
index 2c021a724f98b147a25863ef38a96cbde2ec35b7..d5e6afd8acd26f67c172be5c6b01c9bd269b8af7 100644 (file)
@@ -52,7 +52,6 @@
 #include "2geom/angle.h"
 #include "display/snap-indicator.h"
 
-#include "isnan.h" //temp fix.  make sure included last
 
 static void sp_remove_handles(SPKnot *knot[], gint num);
 
@@ -95,8 +94,8 @@ Inkscape::SelTrans::SelTrans(SPDesktop *desktop) :
     _show(SHOW_CONTENT),
     _grabbed(false),
     _show_handles(true),
-    _bbox(NR::Nothing()),
-    _approximate_bbox(NR::Nothing()),
+    _bbox(),
+    _approximate_bbox(),
     _absolute_affine(NR::scale(1,1)),
     _opposite(NR::Point(0,0)),
     _opposite_for_specpoints(NR::Point(0,0)),
@@ -292,8 +291,10 @@ void Inkscape::SelTrans::grab(NR::Point const &p, gdouble x, gdouble y, bool sho
 
     // Next, get all points to consider for snapping
     SnapManager const &m = _desktop->namedview->snap_manager;
-    _snap_points = selection->getSnapPoints(m.getIncludeItemCenter());
-    std::vector<NR::Point> snap_points_hull = selection->getSnapPointsConvexHull();
+    _snap_points.clear();
+    to_2geom(selection->getSnapPoints(m.getIncludeItemCenter()), _snap_points);
+    std::vector<Geom::Point> snap_points_hull;
+    to_2geom(selection->getSnapPointsConvexHull(), snap_points_hull);
     if (_snap_points.size() > 100) {
         /* Snapping a huge number of nodes will take way too long, so limit the number of snappable nodes
         An average user would rarely ever try to snap such a large number of nodes anyway, because
@@ -307,7 +308,7 @@ void Inkscape::SelTrans::grab(NR::Point const &p, gdouble x, gdouble y, bool sho
     // any other special points
     NR::Rect snap_points_bbox;
     if ( snap_points_hull.empty() == false ) {
-        std::vector<NR::Point>::iterator i = snap_points_hull.begin();
+        std::vector<Geom::Point>::iterator i = snap_points_hull.begin();
         snap_points_bbox = NR::Rect(*i, *i);
         i++;
         while (i != snap_points_hull.end()) {
@@ -320,7 +321,7 @@ void Inkscape::SelTrans::grab(NR::Point const &p, gdouble x, gdouble y, bool sho
     if (_bbox) {
         // ... and add the bbox corners to _bbox_points
         for ( unsigned i = 0 ; i < 4 ; i++ ) {
-            _bbox_points.push_back(_bbox->corner(i));
+            _bbox_points.push_back(to_2geom(_bbox->corner(i)));
         }
         // There are two separate "opposites" (i.e. opposite w.r.t. the handle being dragged):
         //  - one for snapping the boundingbox, which can be either visual or geometric
@@ -611,7 +612,7 @@ void Inkscape::SelTrans::_updateHandles()
         sp_knot_hide(_chandle);
     } else {
         sp_knot_show(_chandle);
-        sp_knot_moveto(_chandle, &*_center);
+        sp_knot_moveto(_chandle, *_center);
     }
 }
 
@@ -682,7 +683,7 @@ void Inkscape::SelTrans::_showHandles(SPKnot *knot[], SPSelTransHandle const han
                      + ( _bbox->dimensions()
                          * NR::scale(handle_pt) ) );
 
-        sp_knot_moveto(knot[i], &p);
+        sp_knot_moveto(knot[i], p);
     }
 }
 
@@ -808,7 +809,7 @@ gboolean Inkscape::SelTrans::handleRequest(SPKnot *knot, NR::Point *position, gu
         return TRUE;
     }
     if (handle.request(this, handle, *position, state)) {
-        sp_knot_set_position(knot, position, state);
+        sp_knot_set_position(knot, *position, state);
         SP_CTRL(_grip)->moveto(*position);
         SP_CTRL(_norm)->moveto(_origin);
     }
@@ -918,7 +919,7 @@ gboolean Inkscape::SelTrans::scaleRequest(NR::Point &pt, guint state)
     } else {
         // In all other cases we should try to snap now
         SnapManager &m = _desktop->namedview->snap_manager;
-        m.setup(NULL, _items_const);
+        m.setup(_desktop, false, _items_const);
 
         Inkscape::SnappedPoint bb, sn;
         NR::Coord bd(NR_HUGE);
@@ -937,22 +938,26 @@ gboolean Inkscape::SelTrans::scaleRequest(NR::Point &pt, guint state)
             }
 
             // Snap along a suitable constraint vector from the origin.
-            bb = m.constrainedSnapScale(Snapper::SNAPPOINT_BBOX, _bbox_points, default_scale, _origin_for_bboxpoints);
-            sn = m.constrainedSnapScale(Snapper::SNAPPOINT_NODE, _snap_points, geom_scale, _origin_for_specpoints);
+            Geom::Scale default_scale_2geom = to_2geom(default_scale);
+            Geom::Scale geom_scale_2geom = to_2geom(geom_scale);
+            bb = m.constrainedSnapScale(Snapper::SNAPPOINT_BBOX, _bbox_points, default_scale_2geom, to_2geom(_origin_for_bboxpoints));
+            sn = m.constrainedSnapScale(Snapper::SNAPPOINT_NODE, _snap_points, geom_scale_2geom, to_2geom(_origin_for_specpoints));
 
             /* Choose the smaller difference in scale.  Since s[X] == s[Y] we can
             ** just compare difference in s[X].
             */
-            bd = bb.getSnapped() ? fabs(bb.getTransformation()[NR::X] - default_scale[NR::X]) : NR_HUGE;
-            sd = sn.getSnapped() ? fabs(sn.getTransformation()[NR::X] - geom_scale[NR::X]) : NR_HUGE;
+            bd = bb.getSnapped() ? fabs(bb.getTransformation()[NR::X] - default_scale_2geom[Geom::X]) : NR_HUGE;
+            sd = sn.getSnapped() ? fabs(sn.getTransformation()[NR::X] - geom_scale_2geom[Geom::X]) : NR_HUGE;
         } else {
             /* Scale aspect ratio is unlocked */
-            bb = m.freeSnapScale(Snapper::SNAPPOINT_BBOX, _bbox_points, default_scale, _origin_for_bboxpoints);
-            sn = m.freeSnapScale(Snapper::SNAPPOINT_NODE, _snap_points, geom_scale, _origin_for_specpoints);
+            Geom::Scale default_scale_2geom = to_2geom(default_scale);
+            Geom::Scale geom_scale_2geom = to_2geom(geom_scale);
+            bb = m.freeSnapScale(Snapper::SNAPPOINT_BBOX, _bbox_points, default_scale_2geom, to_2geom(_origin_for_bboxpoints));
+            sn = m.freeSnapScale(Snapper::SNAPPOINT_NODE, _snap_points, geom_scale_2geom, to_2geom(_origin_for_specpoints));
 
             /* Pick the snap that puts us closest to the original scale */
-            bd = bb.getSnapped() ? fabs(NR::L2(bb.getTransformation()) - NR::L2(default_scale.point())) : NR_HUGE;
-            sd = sn.getSnapped() ? fabs(NR::L2(sn.getTransformation()) - NR::L2(geom_scale.point())) : NR_HUGE;
+            bd = bb.getSnapped() ? fabs(NR::L2(bb.getTransformation()) - NR::L2(NR::Point(default_scale_2geom[Geom::X], default_scale_2geom[Geom::Y]))) : NR_HUGE;
+            sd = sn.getSnapped() ? fabs(NR::L2(sn.getTransformation()) - NR::L2(NR::Point(geom_scale_2geom[Geom::X], geom_scale_2geom[Geom::Y]))) : NR_HUGE;
         }
 
         if (!(bb.getSnapped() || sn.getSnapped())) {
@@ -1027,7 +1032,7 @@ gboolean Inkscape::SelTrans::stretchRequest(SPSelTransHandle const &handle, NR::
         // In all other cases we should try to snap now
 
         SnapManager &m = _desktop->namedview->snap_manager;
-        m.setup(NULL, _items_const);
+        m.setup(_desktop, false, _items_const);
 
         Inkscape::SnappedPoint bb, sn;
         g_assert(bb.getSnapped() == false); // Check initialization to catch any regression
@@ -1036,41 +1041,44 @@ gboolean Inkscape::SelTrans::stretchRequest(SPSelTransHandle const &handle, NR::
 
         bool symmetrical = state & GDK_CONTROL_MASK;
 
-        bb = m.constrainedSnapStretch(Snapper::SNAPPOINT_BBOX, _bbox_points, default_scale[axis], _origin_for_bboxpoints, axis, symmetrical);
-        sn = m.constrainedSnapStretch(Snapper::SNAPPOINT_NODE, _snap_points, geom_scale[axis], _origin_for_specpoints, axis, symmetrical);
+        Geom::Scale default_scale_2geom = to_2geom(default_scale);
+        Geom::Scale geom_scale_2geom = to_2geom(geom_scale);
+
+        bb = m.constrainedSnapStretch(Snapper::SNAPPOINT_BBOX, _bbox_points, Geom::Coord(default_scale_2geom[axis]), to_2geom(_origin_for_bboxpoints), Geom::Dim2(axis), symmetrical);
+        sn = m.constrainedSnapStretch(Snapper::SNAPPOINT_NODE, _snap_points, Geom::Coord(geom_scale_2geom[axis]), to_2geom(_origin_for_specpoints), Geom::Dim2(axis), symmetrical);
 
         if (bb.getSnapped()) {
             // We snapped the bbox (which is either visual or geometric)
-            bd = fabs(bb.getTransformation()[axis] - default_scale[axis]);
-            default_scale[axis] = bb.getTransformation()[axis];
+            bd = fabs(bb.getTransformation()[axis] - default_scale_2geom[axis]);
+            default_scale_2geom[axis] = bb.getTransformation()[axis];
         }
 
         if (sn.getSnapped()) {
-            sd = fabs(sn.getTransformation()[axis] - geom_scale[axis]);
-            geom_scale[axis] = sn.getTransformation()[axis];
+            sd = fabs(sn.getTransformation()[axis] - geom_scale_2geom[axis]);
+            geom_scale_2geom[axis] = sn.getTransformation()[axis];
         }
 
         if (symmetrical) {
             // on ctrl, apply symmetrical scaling instead of stretching
             // Preserve aspect ratio, but never flip in the dimension not being edited (by using fabs())
-            default_scale[perp] = fabs(default_scale[axis]);
-            geom_scale[perp] = fabs(geom_scale[axis]);
+            default_scale_2geom[perp] = fabs(default_scale_2geom[axis]);
+            geom_scale_2geom[perp] = fabs(geom_scale_2geom[axis]);
         }
 
         if (!(bb.getSnapped() || sn.getSnapped())) {
             // We didn't snap at all! Don't update the handle position, just calculate the new transformation
-            _calcAbsAffineDefault(default_scale);
+            _calcAbsAffineDefault(from_2geom(default_scale_2geom));
             _desktop->snapindicator->remove_snappoint();
         } else if (bd < sd) {
             _desktop->snapindicator->set_new_snappoint(bb);
             // Calculate the new transformation and update the handle position
-            pt = _calcAbsAffineDefault(default_scale);
+            pt = _calcAbsAffineDefault(from_2geom(default_scale_2geom));
         } else {
             _desktop->snapindicator->set_new_snappoint(sn);
             // We snapped the special points (e.g. nodes), which are not at the visual bbox
             // The handle location however (pt) might however be at the visual bbox, so we
             // will have to calculate pt taking the stroke width into account
-            pt = _calcAbsAffineGeom(geom_scale);
+            pt = _calcAbsAffineGeom(from_2geom(geom_scale_2geom));
         }
     }
 
@@ -1148,12 +1156,12 @@ gboolean Inkscape::SelTrans::skewRequest(SPSelTransHandle const &handle, NR::Poi
         // Snap to objects, grids, guides
 
         SnapManager &m = _desktop->namedview->snap_manager;
-        m.setup(NULL, _items_const);
+        m.setup(_desktop, false, _items_const);
 
         Inkscape::Snapper::ConstraintLine const constraint(component_vectors[dim_b]);
         NR::Point const s(skew[dim_a], scale[dim_a]);
-        Inkscape::SnappedPoint bb = m.constrainedSnapSkew(Inkscape::Snapper::SNAPPOINT_BBOX, _bbox_points, constraint, s, _origin, dim_b);
-        Inkscape::SnappedPoint sn = m.constrainedSnapSkew(Inkscape::Snapper::SNAPPOINT_NODE, _snap_points, constraint, s, _origin, dim_b);
+        Inkscape::SnappedPoint bb = m.constrainedSnapSkew(Inkscape::Snapper::SNAPPOINT_BBOX, _bbox_points, constraint, to_2geom(s), to_2geom(_origin), Geom::Dim2(dim_b));
+        Inkscape::SnappedPoint sn = m.constrainedSnapSkew(Inkscape::Snapper::SNAPPOINT_NODE, _snap_points, constraint, to_2geom(s), to_2geom(_origin), Geom::Dim2(dim_b));
 
         if (bb.getSnapped() || sn.getSnapped()) {
             // We snapped something, so change the skew to reflect it
@@ -1261,7 +1269,9 @@ gboolean Inkscape::SelTrans::centerRequest(NR::Point &pt, guint state)
 {
     SnapManager &m = _desktop->namedview->snap_manager;
     m.setup(_desktop);
-    m.freeSnapReturnByRef(Snapper::SNAPPOINT_NODE, pt);
+    Geom::Point pt2g = to_2geom(pt);
+    m.freeSnapReturnByRef(Snapper::SNAPPOINT_NODE, pt2g);
+    pt = from_2geom(pt2g);
 
     if (state & GDK_CONTROL_MASK) {
         if ( fabs(_point[NR::X] - pt[NR::X]) > fabs(_point[NR::Y] - pt[NR::Y]) ) {
@@ -1354,10 +1364,10 @@ void sp_sel_trans_center(Inkscape::SelTrans *seltrans, SPSelTransHandle const &,
 void Inkscape::SelTrans::moveTo(NR::Point const &xy, guint state)
 {
     SnapManager &m = _desktop->namedview->snap_manager;
-    m.setup(_desktop, _items_const);
+    m.setup(_desktop, true, _items_const);
 
     /* The amount that we've moved by during this drag */
-    NR::Point dxy = xy - _point;
+    Geom::Point dxy = to_2geom(xy - _point);
 
     bool const alt = (state & GDK_MOD1_MASK);
     bool const control = (state & GDK_CONTROL_MASK);
@@ -1438,22 +1448,22 @@ void Inkscape::SelTrans::moveTo(NR::Point const &xy, guint state)
                 // If we didn't snap, then we should still constrain horizontally or vertically
                 // (When we did snap, then this constraint has already been enforced by
                 // calling constrainedSnapTranslation() above)
-                if (fabs(dxy[NR::X]) > fabs(dxy[NR::Y])) {
-                    dxy[NR::Y] = 0;
+                if (fabs(dxy[Geom::X]) > fabs(dxy[Geom::Y])) {
+                    dxy[Geom::Y] = 0;
                 } else {
-                    dxy[NR::X] = 0;
+                    dxy[Geom::X] = 0;
                 }
             }
         }
     }
     
-    NR::Matrix const move((NR::translate(dxy)));
-    NR::Point const norm(0, 0);
-    transform(move, norm);
+    Geom::Matrix const move((Geom::Translate(dxy)));
+    Geom::Point const norm(0, 0);
+    transform(from_2geom(move), from_2geom(norm));
 
     // status text
-    GString *xs = SP_PX_TO_METRIC_STRING(dxy[NR::X], _desktop->namedview->getDefaultMetric());
-    GString *ys = SP_PX_TO_METRIC_STRING(dxy[NR::Y], _desktop->namedview->getDefaultMetric());
+    GString *xs = SP_PX_TO_METRIC_STRING(dxy[Geom::X], _desktop->namedview->getDefaultMetric());
+    GString *ys = SP_PX_TO_METRIC_STRING(dxy[Geom::Y], _desktop->namedview->getDefaultMetric());
     _message_context.setF(Inkscape::NORMAL_MESSAGE, _("<b>Move</b> by %s, %s; with <b>Ctrl</b> to restrict to horizontal/vertical; with <b>Shift</b> to disable snapping"), xs->str, ys->str);
     g_string_free(xs, TRUE);
     g_string_free(ys, TRUE);