Code

Mnemonics in "Fill and stroke", "Align and distribute", and "Transform" dialogs ...
[inkscape.git] / src / vanishing-point.cpp
index 14bf8d1619ba2f85c5e1b9e82e1e3e7a865b957a..f8e991623ded868fcd43c373feff2f8311bd04b2 100644 (file)
@@ -1,5 +1,3 @@
-#define __VANISHING_POINT_C__
-
 /*
  * Vanishing point for 3D perspectives
  *
@@ -7,6 +5,7 @@
  *   bulia byak <buliabyak@users.sf.net>
  *   Johan Engelen <j.b.c.engelen@ewi.utwente.nl>
  *   Maximilian Albert <Anhalter42@gmx.de>
+ *   Abhishek Sharma
  *
  * Copyright (C) 2005-2007 authors
  *
 #include "event-context.h"
 #include "xml/repr.h"
 #include "perspective-line.h"
+#include "shape-editor.h"
+#include "snap.h"
+#include "sp-namedview.h"
 
-#include "knotholder.h" // FIXME: can we avoid direct access to KnotHolder::update_knots?
+using Inkscape::DocumentUndo;
 
 namespace Box3D {
 
@@ -77,7 +79,7 @@ have_VPs_of_same_perspective (VPDragger *dr1, VPDragger *dr2)
 }
 
 static void
-vp_knot_moved_handler (SPKnot */*knot*/, Geom::Point const *ppointer, guint state, gpointer data)
+vp_knot_moved_handler (SPKnot *knot, Geom::Point const *ppointer, guint state, gpointer data)
 {
     VPDragger *dragger = (VPDragger *) data;
     VPDrag *drag = dragger->parent;
@@ -104,7 +106,7 @@ vp_knot_moved_handler (SPKnot */*knot*/, Geom::Point const *ppointer, guint stat
                 sel_boxes = (*vp)->selectedBoxes(sp_desktop_selection(inkscape_active_desktop()));
 
                 // we create a new perspective ...
-                Persp3D *new_persp = persp3d_create_xml_element (dragger->parent->document, old_persp);
+                Persp3D *new_persp = persp3d_create_xml_element (dragger->parent->document, old_persp->perspective_impl);
 
                 /* ... unlink the boxes from the old one and
                    FIXME: We need to unlink the _un_selected boxes of each VP so that
@@ -120,8 +122,8 @@ vp_knot_moved_handler (SPKnot */*knot*/, Geom::Point const *ppointer, guint stat
             }
             // FIXME: Do we need to create a new dragger as well?
             dragger->updateZOrders ();
-            sp_document_done (sp_desktop_document (inkscape_active_desktop()), SP_VERB_CONTEXT_3DBOX,
-                              _("Split vanishing points"));
+            DocumentUndo::done(sp_desktop_document (inkscape_active_desktop()), SP_VERB_CONTEXT_3DBOX,
+                              _("Split vanishing points"));
             return;
         }
     }
@@ -130,7 +132,7 @@ vp_knot_moved_handler (SPKnot */*knot*/, Geom::Point const *ppointer, guint stat
         // without Shift; see if we need to snap to another dragger
         for (GList *di = dragger->parent->draggers; di != NULL; di = di->next) {
             VPDragger *d_new = (VPDragger *) di->data;
-            if ((d_new != dragger) && (NR::L2 (d_new->point - p) < snap_dist)) {
+            if ((d_new != dragger) && (Geom::L2 (d_new->point - p) < snap_dist)) {
                 if (have_VPs_of_same_perspective (dragger, d_new)) {
                     // this would result in degenerate boxes, which we disallow for the time being
                     continue;
@@ -165,16 +167,26 @@ vp_knot_moved_handler (SPKnot */*knot*/, Geom::Point const *ppointer, guint stat
                 //       deleted according to changes in the svg representation, not based on any user input
                 //       as is currently the case.
 
-                sp_document_done (sp_desktop_document (inkscape_active_desktop()), SP_VERB_CONTEXT_3DBOX,
-                                  _("Merge vanishing points"));
+                DocumentUndo::done(sp_desktop_document (inkscape_active_desktop()), SP_VERB_CONTEXT_3DBOX,
+                                  _("Merge vanishing points"));
 
                 return;
             }
         }
-    }
 
+        // We didn't snap to another dragger, so we'll try a regular snap
+        SPDesktop *desktop = inkscape_active_desktop();
+        SnapManager &m = desktop->namedview->snap_manager;
+        m.setup(desktop);
+        Inkscape::SnappedPoint s = m.freeSnap(Inkscape::SnapCandidatePoint(p, Inkscape::SNAPSOURCE_OTHER_HANDLE));
+        m.unSetup();
+        if (s.getSnapped()) {
+            p = s.getPoint();
+            sp_knot_moveto(knot, p);
+        }
+    }
 
-    dragger->point = p; // FIXME: Brauchen wir dragger->point überhaupt?
+    dragger->point = p; // FIXME: Is dragger->point being used at all?
 
     dragger->updateVPs(p);
     dragger->updateBoxDisplays();
@@ -221,8 +233,8 @@ vp_knot_ungrabbed_handler (SPKnot *knot, guint /*state*/, gpointer data)
     // TODO: Undo machinery!!
     g_return_if_fail (dragger->parent);
     g_return_if_fail (dragger->parent->document);
-    sp_document_done(dragger->parent->document, SP_VERB_CONTEXT_3DBOX,
-                     _("3D box: Move vanishing point"));
+    DocumentUndo::done(dragger->parent->document, SP_VERB_CONTEXT_3DBOX,
+                      _("3D box: Move vanishing point"));
 }
 
 unsigned int VanishingPoint::global_counter = 0;
@@ -231,7 +243,7 @@ unsigned int VanishingPoint::global_counter = 0;
 void
 VanishingPoint::set_pos(Proj::Pt2 const &pt) {
     g_return_if_fail (_persp);
-    _persp->tmat.set_image_pt (_axis, pt);
+    _persp->perspective_impl->tmat.set_image_pt (_axis, pt);
 }
 
 std::list<SPBox3D *>
@@ -457,7 +469,7 @@ VPDragger::updateZOrders ()
 
 void
 VPDragger::printVPs() {
-    g_print ("VPDragger at position (%f, %f):\n", point[NR::X], point[NR::Y]);
+    g_print ("VPDragger at position (%f, %f):\n", point[Geom::X], point[Geom::Y]);
     for (std::list<VanishingPoint>::iterator i = this->vps.begin(); i != this->vps.end(); ++i) {
         g_print ("    VP %s\n", (*i).axisString());
     }
@@ -614,8 +626,8 @@ VPDrag::updateBoxHandles ()
 
     SPEventContext *ec = inkscape_active_event_context();
     g_assert (ec != NULL);
-    if (ec->shape_knot_holder != NULL) {
-        ec->shape_knot_holder->update_knots();
+    if (ec->shape_editor != NULL) {
+        ec->shape_editor->update_knotholder();
     }
 }
 
@@ -725,7 +737,7 @@ VPDrag::addDragger (VanishingPoint &vp)
 
     for (GList *i = this->draggers; i != NULL; i = i->next) {
         VPDragger *dragger = (VPDragger *) i->data;
-        if (NR::L2 (dragger->point - p) < MERGE_DIST) {
+        if (Geom::L2 (dragger->point - p) < MERGE_DIST) {
             // distance is small, merge this draggable into dragger, no need to create new dragger
             dragger->addVP (vp);
             return;
@@ -776,4 +788,4 @@ VPDrag::addLine (Geom::Point p1, Geom::Point p2, guint32 rgba)
   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 :