diff --git a/src/sp-guide.cpp b/src/sp-guide.cpp
index 94f937ff95c304fe9c8f6b2335885abc5e12f7d9..5375bc442d7301d12d06d8e3d7076a42d1eae6ad 100644 (file)
--- a/src/sp-guide.cpp
+++ b/src/sp-guide.cpp
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
+
+#include <algorithm>
+#include <cstring>
+#include <string>
+#include "desktop-handles.h"
#include "display/guideline.h"
#include "svg/svg.h"
#include "svg/stringstream.h"
#include "inkscape.h"
#include "desktop.h"
#include "sp-namedview.h"
+#include <2geom/angle.h>
+#include "document.h"
using std::vector;
@@ -199,6 +206,7 @@ static void sp_guide_set(SPObject *object, unsigned int key, const gchar *value)
// default to vertical line for bad arguments
guide->normal_to_line = component_vectors[NR::X];
}
+ sp_guide_set_normal(*guide, guide->normal_to_line.to_2geom(), false);
}
break;
case SP_ATTR_POSITION:
@@ -233,6 +241,52 @@ static void sp_guide_set(SPObject *object, unsigned int key, const gchar *value)
}
}
+SPGuide *
+sp_guide_create(SPDesktop *desktop, Geom::Point const &pt1, Geom::Point const &pt2) {
+ SPDocument *doc=sp_desktop_document(desktop);
+ Inkscape::XML::Document *xml_doc = sp_document_repr_doc(doc);
+
+ Inkscape::XML::Node *repr = xml_doc->createElement("sodipodi:guide");
+
+ Geom::Point n = Geom::rot90(pt2 - pt1);
+
+ sp_repr_set_point(repr, "position", pt1);
+ sp_repr_set_point(repr, "orientation", n);
+
+ SP_OBJECT_REPR(desktop->namedview)->appendChild(repr);
+ Inkscape::GC::release(repr);
+
+ SPGuide *guide= SP_GUIDE(doc->getObjectByRepr(repr));
+ return guide;
+}
+
+void
+sp_guide_pt_pairs_to_guides(SPDesktop *dt, std::list<std::pair<Geom::Point, Geom::Point> > &pts) {
+ for (std::list<std::pair<Geom::Point, Geom::Point> >::iterator i = pts.begin(); i != pts.end(); ++i) {
+ sp_guide_create(dt, (*i).first, (*i).second);
+ }
+}
+
+void
+sp_guide_create_guides_around_page(SPDesktop *dt) {
+ SPDocument *doc=sp_desktop_document(dt);
+ std::list<std::pair<Geom::Point, Geom::Point> > pts;
+
+ Geom::Point A(0, 0);
+ Geom::Point C(sp_document_width(doc), sp_document_height(doc));
+ Geom::Point B(C[Geom::X], 0);
+ Geom::Point D(0, C[Geom::Y]);
+
+ pts.push_back(std::make_pair<Geom::Point, Geom::Point>(A, B));
+ pts.push_back(std::make_pair<Geom::Point, Geom::Point>(B, C));
+ pts.push_back(std::make_pair<Geom::Point, Geom::Point>(C, D));
+ pts.push_back(std::make_pair<Geom::Point, Geom::Point>(D, A));
+
+ sp_guide_pt_pairs_to_guides(dt, pts);
+
+ sp_document_done (doc, SP_VERB_NONE, _("Guides around page"));
+}
+
void sp_guide_show(SPGuide *guide, SPCanvasGroup *group, GCallback handler)
{
SPCanvasItem *item = sp_guideline_new(group, guide->point_on_line, guide->normal_to_line.to_2geom());
@@ -301,10 +355,40 @@ void sp_guide_moveto(SPGuide const &guide, Geom::Point const point_on_line, bool
sp_guideline_set_position(SP_GUIDELINE(l->data), point_on_line);
}
- /* Calling sp_repr_set_svg_double must precede calling sp_item_notify_moveto in the commit
+ /* Calling sp_repr_set_point must precede calling sp_item_notify_moveto in the commit
+ case, so that the guide's new position is available for sp_item_rm_unsatisfied_cns. */
+ if (commit) {
+ sp_repr_set_point(SP_OBJECT(&guide)->repr, "position", point_on_line);
+ }
+
+/* DISABLED CODE BECAUSE SPGuideAttachment IS NOT USE AT THE MOMENT (johan)
+ for (vector<SPGuideAttachment>::const_iterator i(guide.attached_items.begin()),
+ iEnd(guide.attached_items.end());
+ i != iEnd; ++i)
+ {
+ SPGuideAttachment const &att = *i;
+ sp_item_notify_moveto(*att.item, guide, att.snappoint_ix, position, commit);
+ }
+*/
+}
+
+/**
+ * \arg commit False indicates temporary moveto in response to motion event while dragging,
+ * true indicates a "committing" version: in response to button release event after
+ * dragging a guideline, or clicking OK in guide editing dialog.
+ */
+void sp_guide_set_normal(SPGuide const &guide, Geom::Point const normal_to_line, bool const commit)
+{
+ g_assert(SP_IS_GUIDE(&guide));
+
+ for (GSList *l = guide.views; l != NULL; l = l->next) {
+ sp_guideline_set_normal(SP_GUIDELINE(l->data), normal_to_line);
+ }
+
+ /* Calling sp_repr_set_svg_point must precede calling sp_item_notify_moveto in the commit
case, so that the guide's new position is available for sp_item_rm_unsatisfied_cns. */
if (commit) {
- sp_repr_set_svg_point(SP_OBJECT(&guide)->repr, "position", point_on_line);
+ sp_repr_set_point(SP_OBJECT(&guide)->repr, "orientation", normal_to_line);
}
/* DISABLED CODE BECAUSE SPGuideAttachment IS NOT USE AT THE MOMENT (johan)
GString *position_string_x = SP_PX_TO_METRIC_STRING(guide->point_on_line[X], SP_ACTIVE_DESKTOP->namedview->getDefaultMetric());
GString *position_string_y = SP_PX_TO_METRIC_STRING(guide->point_on_line[Y], SP_ACTIVE_DESKTOP->namedview->getDefaultMetric());
- if ( guide->normal_to_line == component_vectors[X] ) {
- return g_strdup_printf(_("vertical guideline at %s"), position_string_x->str);
- } else if ( guide->normal_to_line == component_vectors[Y] ) {
- return g_strdup_printf(_("horizontal guideline at %s"), position_string_y->str);
+ if ( guide->normal_to_line == component_vectors[X] ||
+ guide->normal_to_line == -component_vectors[X]) {
+ return g_strdup_printf(_("vertical, at %s"), position_string_x->str);
+ } else if ( guide->normal_to_line == component_vectors[Y] ||
+ guide->normal_to_line == -component_vectors[Y]) {
+ return g_strdup_printf(_("horizontal, at %s"), position_string_y->str);
} else {
- double const radians = atan2(guide->normal_to_line[X],
- guide->normal_to_line[Y]);
- /* flip y axis and rotate 90 degrees to convert to line angle */
- double const degrees = ( radians / M_PI ) * 180.0;
- int const degrees_int = (int) floor( degrees + .5 );
- return g_strdup_printf("%d degree guideline at (%s,%s)", degrees_int, position_string_x->str, position_string_y->str);
- /* Alternative suggestion: "angled guideline". */
+ double const radians = guide->angle();
+ double const degrees = Geom::rad_to_deg(radians);
+ int const degrees_int = (int) round(degrees);
+ return g_strdup_printf(_("at %d degrees, through (%s,%s); <b>Ctrl</b>+click to delete"), degrees_int, position_string_x->str, position_string_y->str);
}
g_string_free(position_string_x, TRUE);