Code

Add a warning to sp-object.h to not use some of the new methods
[inkscape.git] / src / draw-context.cpp
index ca68b3f6df0fe66aa0b9beed444c584ee6a8c752..62ae67336cad48236adbbcb3c29132257aa716b6 100644 (file)
@@ -1,10 +1,9 @@
-#define __SP_DRAW_CONTEXT_C__
-
 /*
  * Generic drawing context
  *
  * Author:
  *   Lauris Kaplinski <lauris@kaplinski.com>
+ *   Abhishek Sharma
  *
  * Copyright (C) 2000 Lauris Kaplinski
  * Copyright (C) 2000-2001 Ximian, Inc.
@@ -42,7 +41,8 @@
 #include "sp-namedview.h"
 #include "live_effects/lpe-patternalongpath.h"
 #include "style.h"
-#include "util/mathfns.h"
+
+using Inkscape::DocumentUndo;
 
 static void sp_draw_context_class_init(SPDrawContextClass *klass);
 static void sp_draw_context_init(SPDrawContext *dc);
@@ -439,7 +439,7 @@ spdc_attach_selection(SPDrawContext *dc, Inkscape::Selection */*sel*/)
         /* Curve list */
         /* We keep it in desktop coordinates to eliminate calculation errors */
         SPCurve *norm = sp_path_get_curve_for_edit (SP_PATH(item));
-        norm->transform(sp_item_i2d_affine(dc->white_item));
+        norm->transform((dc->white_item)->i2d_affine());
         g_return_if_fail( norm != NULL );
         dc->white_curves = g_slist_reverse(norm->split());
         norm->unref();
@@ -477,43 +477,26 @@ void spdc_endpoint_snap_rotation(SPEventContext const *const ec, Geom::Point &p,
 {
     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
     unsigned const snaps = abs(prefs->getInt("/options/rotationsnapsperpi/value", 12));
+    SnapManager &m = SP_EVENT_CONTEXT_DESKTOP(ec)->namedview->snap_manager;
+    m.setup(SP_EVENT_CONTEXT_DESKTOP(ec));
 
-    if (snaps > 0) { // 0 means no snapping
-        // p is at an arbitrary angle. Now we should snap this angle to specific increments.
-        // For this we'll calculate the closest two angles, one at each side of the current angle
-        Geom::Line y_axis(Geom::Point(0, 0), Geom::Point(0, 1));
-        Geom::Line p_line(o, p);
-        double angle = Geom::angle_between(y_axis, p_line);
-        double angle_incr = M_PI / snaps;
-        double angle_ceil = round_to_upper_multiple_plus(angle, angle_incr);
-        double angle_floor = round_to_lower_multiple_plus(angle, angle_incr);
-        // We have to angles now. The constrained snapper will try each of them and return the closest
-        // But first we should setup the snapper
-
-        SnapManager &m = SP_EVENT_CONTEXT_DESKTOP(ec)->namedview->snap_manager;
-        m.setup(SP_EVENT_CONTEXT_DESKTOP(ec));
-        bool snap_enabled = m.snapprefs.getSnapEnabledGlobally();
-        if (state & GDK_SHIFT_MASK) {
-            // SHIFT disables all snapping, except the angular snapping. After all, the user explicitly asked for angular
-            // snapping by pressing CTRL, otherwise we wouldn't have arrived here. But although we temporarily disable
-            // the snapping here, we must still call for a constrained snap in order to apply the constraints (i.e. round
-            // to the nearest angle increment)
-            m.snapprefs.setSnapEnabledGlobally(false);
-        }
-
-        // Now do the snapping...
-        std::vector<Inkscape::Snapper::SnapConstraint> constraints;
-        constraints.push_back(Inkscape::Snapper::SnapConstraint(Geom::Line(o, angle_ceil - M_PI/2)));
-        constraints.push_back(Inkscape::Snapper::SnapConstraint(Geom::Line(o, angle_floor - M_PI/2)));
+    bool snap_enabled = m.snapprefs.getSnapEnabledGlobally();
+    if (state & GDK_SHIFT_MASK) {
+        // SHIFT disables all snapping, except the angular snapping. After all, the user explicitly asked for angular
+        // snapping by pressing CTRL, otherwise we wouldn't have arrived here. But although we temporarily disable
+        // the snapping here, we must still call for a constrained snap in order to apply the constraints (i.e. round
+        // to the nearest angle increment)
+        m.snapprefs.setSnapEnabledGlobally(false);
+    }
 
-        Inkscape::SnappedPoint sp = m.multipleConstrainedSnaps(Inkscape::SnapCandidatePoint(p, Inkscape::SNAPSOURCE_NODE_HANDLE), constraints);
-        p = sp.getPoint();
+    Inkscape::SnappedPoint dummy = m.constrainedAngularSnap(Inkscape::SnapCandidatePoint(p, Inkscape::SNAPSOURCE_NODE_HANDLE), boost::optional<Geom::Point>(), o, snaps);
+    p = dummy.getPoint();
 
-        m.unSetup();
-        if (state & GDK_SHIFT_MASK) {
-            m.snapprefs.setSnapEnabledGlobally(snap_enabled); // restore the original setting
-        }
+    if (state & GDK_SHIFT_MASK) {
+        m.snapprefs.setSnapEnabledGlobally(snap_enabled); // restore the original setting
     }
+
+    m.unSetup();
 }
 
 
@@ -657,12 +640,12 @@ spdc_flush_white(SPDrawContext *dc, SPCurve *gc)
 
     /* Now we have to go back to item coordinates at last */
     c->transform( dc->white_item
-                            ? sp_item_dt2i_affine(dc->white_item)
+                            ? (dc->white_item)->dt2i_affine()
                             : SP_EVENT_CONTEXT_DESKTOP(dc)->dt2doc() );
 
     SPDesktop *desktop = SP_EVENT_CONTEXT_DESKTOP(dc);
     SPDocument *doc = sp_desktop_document(desktop);
-    Inkscape::XML::Document *xml_doc = sp_document_repr_doc(doc);
+    Inkscape::XML::Document *xml_doc = doc->getReprDoc();
 
     if ( c && !c->is_empty() ) {
         /* We actually have something to write */
@@ -695,11 +678,11 @@ spdc_flush_white(SPDrawContext *dc, SPCurve *gc)
 
             dc->selection->set(repr);
             Inkscape::GC::release(repr);
-            item->transform = sp_item_i2doc_affine(SP_ITEM(desktop->currentLayer())).inverse();
+            item->transform = SP_ITEM(desktop->currentLayer())->i2doc_affine().inverse();
             item->updateRepr();
         }
 
-        sp_document_done(doc, SP_IS_PEN_CONTEXT(dc)? SP_VERB_CONTEXT_PEN : SP_VERB_CONTEXT_PENCIL,
+        DocumentUndo::done(doc, SP_IS_PEN_CONTEXT(dc)? SP_VERB_CONTEXT_PEN : SP_VERB_CONTEXT_PENCIL,
                          _("Draw path"));
 
         // When quickly drawing several subpaths with Shift, the next subpath may be finished and
@@ -713,7 +696,7 @@ spdc_flush_white(SPDrawContext *dc, SPCurve *gc)
     c->unref();
 
     /* Flush pending updates */
-    sp_document_ensure_up_to_date(doc);
+    doc->ensureUpToDate();
 }
 
 /**
@@ -807,7 +790,7 @@ void spdc_create_single_dot(SPEventContext *ec, Geom::Point const &pt, char cons
     Glib::ustring tool_path = tool;
 
     SPDesktop *desktop = SP_EVENT_CONTEXT_DESKTOP(ec);
-    Inkscape::XML::Document *xml_doc = sp_document_repr_doc(desktop->doc());
+    Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc();
     Inkscape::XML::Node *repr = xml_doc->createElement("svg:path");
     repr->setAttribute("sodipodi:type", "arc");
     SPItem *item = SP_ITEM(desktop->currentLayer()->appendChildRepr(repr));
@@ -837,8 +820,8 @@ void spdc_create_single_dot(SPEventContext *ec, Geom::Point const &pt, char cons
        current stroke width, multiplied by the amount specified in the preferences */
     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
 
-    Geom::Matrix const i2d (sp_item_i2d_affine (item));
-    Geom::Point pp = pt * i2d.inverse();
+    Geom::Matrix const i2d (item->i2d_affine ());
+    Geom::Point pp = pt;
     double rad = 0.5 * prefs->getDouble(tool_path + "/dot-size", 3.0);
     if (event_state & GDK_MOD1_MASK) {
         /* TODO: We vary the dot size between 0.5*rad and 1.5*rad, where rad is the dot size
@@ -857,11 +840,12 @@ void spdc_create_single_dot(SPEventContext *ec, Geom::Point const &pt, char cons
     sp_repr_set_svg_double (repr, "sodipodi:rx", rad * stroke_width);
     sp_repr_set_svg_double (repr, "sodipodi:ry", rad * stroke_width);
     item->updateRepr();
+    item->set_item_transform(i2d.inverse());
 
     sp_desktop_selection(desktop)->set(item);
 
     desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Creating single dot"));
-    sp_document_done(sp_desktop_document(desktop), SP_VERB_NONE, _("Create single dot"));
+    DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_NONE, _("Create single dot"));
 }
 
 /*
@@ -873,4 +857,4 @@ void spdc_create_single_dot(SPEventContext *ec, Geom::Point const &pt, char cons
   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 :