index 16e579d16317e1968c856b0ba28a0cb95594609f..1214a1766db3281d66926d12c91bcd9475159468 100644 (file)
#include "live_effects/parameter/path.h"
#include "live_effects/effect.h"
-#include "libnr/n-art-bpath-2geom.h"
#include "svg/svg.h"
#include <2geom/svg-path-parser.h>
#include <2geom/sbasis-to-bezier.h>
+#include <2geom/pathvector.h>
#include <2geom/d2.h>
#include "ui/widget/point.h"
const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr,
Effect* effect, const gchar * default_value)
: Parameter(label, tip, key, wr, effect),
+ changed(true),
_pathvector(),
_pwd2(),
must_recalculate_pwd2(false),
_pathvector = sp_svg_read_pathv(strvalue);
}
- signal_path_changed.emit();
+ emit_changed();
return true;
}
{
// If not already in nodecontext, goto it!
if (!tools_isactive(dt, TOOLS_NODES)) {
- tools_switch_current(TOOLS_NODES);
+ tools_switch(dt, TOOLS_NODES);
}
- ShapeEditor * shape_editor = SP_NODE_CONTEXT( dt->event_context )->shape_editor;
+ ShapeEditor * shape_editor = dt->event_context->shape_editor;
if (!href) {
shape_editor->set_item_lpe_path_parameter(item, SP_OBJECT(param_effect->getLPEObj()), param_key.c_str());
} else {
// set referred item for editing
- shape_editor->set_item(ref.getObject());
+ shape_editor->set_item(ref.getObject(), SH_NODEPATH);
}
}
np->helperpath_width = 1.0;
}
+void
+PathParam::addCanvasIndicators(SPLPEItem */*lpeitem*/, std::vector<Geom::PathVector> &hp_vec)
+{
+ hp_vec.push_back(_pathvector);
+}
+
+/*
+ * Only applies transform when not referring to other path!
+ */
void
PathParam::param_transform_multiply(Geom::Matrix const& postmul, bool /*set*/)
{
+ // only apply transform when not referring to other path
if (!href) {
- // TODO: recode this to apply transform to _pathvector instead?
-
- // only apply transform when not referring to other path
- ensure_pwd2();
- param_set_and_write_new_value( _pwd2 * postmul );
+ set_new_value( _pathvector * postmul, true );
}
}
+/*
+ * See comments for set_new_value(std::vector<Geom::Path>).
+ */
void
-PathParam::param_set_and_write_new_value (Geom::Piecewise<Geom::D2<Geom::SBasis> > const & newpath)
+PathParam::set_new_value (Geom::Piecewise<Geom::D2<Geom::SBasis> > const & newpath, bool write_to_svg)
{
remove_link();
_pathvector = Geom::path_from_piecewise(newpath, LPE_CONVERSION_TOLERANCE);
- gchar * svgd = sp_svg_write_path( _pathvector );
- param_write_to_repr(svgd);
- g_free(svgd);
- // force value upon pwd2 and don't recalculate.
- _pwd2 = newpath;
- must_recalculate_pwd2 = false;
+
+ if (write_to_svg) {
+ gchar * svgd = sp_svg_write_path( _pathvector );
+ param_write_to_repr(svgd);
+ g_free(svgd);
+
+ // After the whole "writing to svg avalanche of function calling": force value upon pwd2 and don't recalculate.
+ _pwd2 = newpath;
+ must_recalculate_pwd2 = false;
+ } else {
+ _pwd2 = newpath;
+ must_recalculate_pwd2 = false;
+ emit_changed();
+ }
}
+/*
+ * This method sets new path data.
+ * If this PathParam refers to another path, this link is removed (and replaced with explicit path data).
+ *
+ * If write_to_svg = true :
+ * The new path data is written to SVG. In this case the signal_path_changed signal
+ * is not directly emited in this method, because writing to SVG
+ * triggers the LPEObject to which this belongs to call Effect::setParameter which calls
+ * PathParam::readSVGValue, which finally emits the signal_path_changed signal.
+ * If write_to_svg = false :
+ * The new path data is not written to SVG. This method will emit the signal_path_changed signal.
+ */
void
-PathParam::param_set_and_write_new_value (std::vector<Geom::Path> const & newpath)
+PathParam::set_new_value (std::vector<Geom::Path> const &newpath, bool write_to_svg)
{
remove_link();
_pathvector = newpath;
must_recalculate_pwd2 = true;
- gchar * svgd = sp_svg_write_path( _pathvector );
- param_write_to_repr(svgd);
- g_free(svgd);
+ if (write_to_svg) {
+ gchar * svgd = sp_svg_write_path( _pathvector );
+ param_write_to_repr(svgd);
+ g_free(svgd);
+ } else {
+ emit_changed();
+ }
}
void
}
}
+void
+PathParam::emit_changed()
+{
+ changed = true;
+ signal_path_changed.emit();
+}
+
void
PathParam::start_listening(SPObject * to)
{
{
quit_listening();
remove_link();
- param_set_and_write_new_value (_pathvector);
+ set_new_value (_pathvector, true);
}
void
}
must_recalculate_pwd2 = true;
- signal_path_changed.emit();
+ emit_changed();
SP_OBJECT(param_effect->getLPEObj())->requestModified(SP_OBJECT_MODIFIED_FLAG);
}
void
PathParam::paste_param_path(const char *svgd)
{
- if (svgd == "")
- return;
-
- // remove possible link to path
- remove_link();
+ // only recognize a non-null, non-empty string
+ if (svgd && *svgd) {
+ // remove possible link to path
+ remove_link();
- param_write_to_repr(svgd);
- signal_path_pasted.emit();
- sp_document_done(param_effect->getSPDoc(), SP_VERB_DIALOG_LIVE_PATH_EFFECT,
- _("Paste path parameter"));
+ param_write_to_repr(svgd);
+ signal_path_pasted.emit();
+ }
}
void
Inkscape::UI::ClipboardManager *cm = Inkscape::UI::ClipboardManager::get();
Glib::ustring svgd = cm->getPathParameter();
paste_param_path(svgd.data());
+ sp_document_done(param_effect->getSPDoc(), SP_VERB_DIALOG_LIVE_PATH_EFFECT,
+ _("Paste path parameter"));
}
void
// check if linking to object to which LPE is applied (maybe delegated to PathReference
param_write_to_repr(pathid.c_str());
- sp_document_done(param_effect->getSPDoc(), SP_VERB_DIALOG_LIVE_PATH_EFFECT,
+ sp_document_done(param_effect->getSPDoc(), SP_VERB_DIALOG_LIVE_PATH_EFFECT,
_("Link path parameter to path"));
}
}