Code

* Merge from trunk
[inkscape.git] / src / ui / tool / node.cpp
index adef8e5a7e93b3fc7f7f9489427ba9828e7caef7..303c0fb75b6bf6f2a40e286eb85246761c13de71 100644 (file)
@@ -71,7 +71,10 @@ static Geom::Point direction(Geom::Point const &first, Geom::Point const &second
 
 /**
  * @class Handle
- * Represents a control point of a cubic Bezier curve in a path.
+ * @brief Control point of a cubic Bezier curve in a path.
+ *
+ * Handle keeps the node type invariant only for the opposite handle of the same node.
+ * Keeping the invariant on node moves is left to the %Node class.
  */
 
 double Handle::_saved_length = 0.0;
@@ -320,7 +323,9 @@ Glib::ustring Handle::_getDragTip(GdkEventMotion *event)
 
 /**
  * @class Node
- * Represents a curve endpoint in an editable path.
+ * @brief Curve endpoint in an editable path.
+ *
+ * The method move() keeps node type invariants during translations.
  */
 
 Node::Node(NodeSharedData const &data, Geom::Point const &initial_pos)
@@ -554,6 +559,8 @@ void Node::setType(NodeType type, bool update_handles)
     updateState();
 }
 
+/** Pick the best type for this node, based on the position of its handles.
+ * This is what assigns types to nodes created using the pen tool. */
 void Node::pickBestType()
 {
     _type = NODE_CUSP;
@@ -652,7 +659,7 @@ bool Node::_eventHandler(GdkEvent *event)
     return ControlPoint::_eventHandler(event);
 }
 
-// TODO Move this to 2Geom
+// TODO Move this to 2Geom!
 static double bezier_length (Geom::Point a0, Geom::Point a1, Geom::Point a2, Geom::Point a3)
 {
     double lower = Geom::distance(a0, a3);
@@ -842,13 +849,14 @@ void Node::_draggedHandler(Geom::Point &new_pos, GdkEventMotion *event)
     SnapManager &sm = _desktop->namedview->snap_manager;
     Inkscape::SnapPreferences::PointType t = Inkscape::SnapPreferences::SNAPPOINT_NODE;
     bool snap = sm.someSnapperMightSnap();
-    std::vector< std::pair<Geom::Point, int> > unselected;
+    std::vector<Inkscape::SnapCandidatePoint> unselected;
     if (snap) {
-        // setup
-        // TODO we are doing this every time a snap happens. It should once be done only once
-        //      per drag - maybe in the grabbed handler?
-        // TODO "unselected" must be valid during the snap run, because it is not copied.
-        //      Fix this in snap.h and snap.cpp, then the above.
+        /* setup
+         * TODO We are doing this every time a snap happens. It should once be done only once
+         *      per drag - maybe in the grabbed handler?
+         * TODO Unselected nodes vector must be valid during the snap run, because it is not
+         *      copied. Fix this in snap.h and snap.cpp, then the above.
+         * TODO Snapping to unselected segments of selected paths doesn't work yet. */
 
         // Build the list of unselected nodes.
         typedef ControlPointSelection::Set Set;
@@ -856,7 +864,8 @@ void Node::_draggedHandler(Geom::Point &new_pos, GdkEventMotion *event)
         for (Set::iterator i = nodes.begin(); i != nodes.end(); ++i) {
             if (!(*i)->selected()) {
                 Node *n = static_cast<Node*>(*i);
-                unselected.push_back(std::make_pair((*i)->position(), (int) n->_snapTargetType()));
+                Inkscape::SnapCandidatePoint p(n->position(), n->_snapSourceType(), n->_snapTargetType());
+                unselected.push_back(p);
             }
         }
         sm.setupIgnoreSelection(_desktop, true, &unselected);
@@ -873,8 +882,8 @@ void Node::_draggedHandler(Geom::Point &new_pos, GdkEventMotion *event)
             // TODO: combine these two branches by modifying snap.h / snap.cpp
             if (snap) {
                 Inkscape::SnappedPoint fp, bp;
-                fp = sm.constrainedSnap(t, position(), _snapSourceType(), line_front);
-                bp = sm.constrainedSnap(t, position(), _snapSourceType(), line_back);
+                fp = sm.constrainedSnap(t, Inkscape::SnapCandidatePoint(position(), _snapSourceType()), line_front);
+                bp = sm.constrainedSnap(t, Inkscape::SnapCandidatePoint(position(), _snapSourceType()), line_back);
 
                 if (fp.isOtherSnapBetter(bp, false)) {
                     bp.getPoint(new_pos);
@@ -897,8 +906,8 @@ void Node::_draggedHandler(Geom::Point &new_pos, GdkEventMotion *event)
                 Inkscape::SnappedPoint fp, bp;
                 Inkscape::Snapper::ConstraintLine line_x(origin, Geom::Point(1, 0));
                 Inkscape::Snapper::ConstraintLine line_y(origin, Geom::Point(0, 1));
-                fp = sm.constrainedSnap(t, position(), _snapSourceType(), line_x);
-                bp = sm.constrainedSnap(t, position(), _snapSourceType(), line_y);
+                fp = sm.constrainedSnap(t, Inkscape::SnapCandidatePoint(position(), _snapSourceType()), line_x);
+                bp = sm.constrainedSnap(t, Inkscape::SnapCandidatePoint(position(), _snapSourceType()), line_y);
 
                 if (fp.isOtherSnapBetter(bp, false)) {
                     fp = bp;