diff --git a/src/shape-editor.cpp b/src/shape-editor.cpp
index 1a0f319da0b362ea1bc027051e70d63e6bcf27a8..fbf42eaca1b8ebc71f1ce116c0db6036b134a5af 100644 (file)
--- a/src/shape-editor.cpp
+++ b/src/shape-editor.cpp
#include "config.h"
#endif
+#include <string.h>
#include <glibmm/i18n.h>
#include "sp-object.h"
#include "sp-item.h"
+#include "live_effects/lpeobject.h"
#include "selection.h"
#include "desktop.h"
#include "desktop-handles.h"
#include "shape-editor.h"
-ShapeEditorsCollective::ShapeEditorsCollective(SPDesktop *dt) {
+ShapeEditorsCollective::ShapeEditorsCollective(SPDesktop */*dt*/) {
}
ShapeEditorsCollective::~ShapeEditorsCollective() {
}
bool ShapeEditor::has_local_change () {
- if (this->nodepath)
+ if (this->nodepath)
return (this->nodepath->local_change != 0);
- else if (this->knotholder)
+ else if (this->knotholder)
return (this->knotholder->local_change != 0);
else
return false;
SPItem *ShapeEditor::get_item () {
SPItem *item = NULL;
if (this->has_nodepath()) {
- item = SP_ITEM(this->nodepath->path);
+ item = this->nodepath->item;
} else if (this->has_knotholder()) {
item = SP_ITEM(this->knotholder->item);
}
::restore_nodepath_selection (this->nodepath, saved);
}
+bool ShapeEditor::nodepath_edits_repr_key(gchar const *name) {
+ if (nodepath && name) {
+ return ( !strcmp(name, nodepath->repr_key) || !strcmp(name, nodepath->repr_nodetypes_key) );
+ }
+
+ return false;
+}
-static void shapeeditor_event_attr_changed(Inkscape::XML::Node *repr, gchar const *name,
- gchar const *old_value, gchar const *new_value,
- bool is_interactive, gpointer data)
+static void shapeeditor_event_attr_changed(Inkscape::XML::Node */*repr*/, gchar const *name,
+ gchar const */*old_value*/, gchar const */*new_value*/,
+ bool /*is_interactive*/, gpointer data)
{
- SPItem *item = NULL;
gboolean changed = FALSE;
g_assert(data);
ShapeEditor *sh = ((ShapeEditor *) data);
- item = sh->get_item();
-
- if (
- ((sh->has_nodepath()) && (!strcmp(name, "d") || !strcmp(name, "sodipodi:nodetypes"))) // With paths, we only need to act if one of the path-affecting attributes has changed.
- || sh->has_knotholder()) {
- changed = !sh->has_local_change();
+ if ( sh->has_knotholder() || ( sh->has_nodepath() && sh->nodepath_edits_repr_key(name) ) )
+ {
+ changed = !sh->has_local_change();
sh->decrement_local_change();
}
@@ -157,7 +162,7 @@ static void shapeeditor_event_attr_changed(Inkscape::XML::Node *repr, gchar cons
saved = sh->save_nodepath_selection();
}
- sh->set_item (item);
+ sh->reset_item ();
if (sh->has_nodepath() && saved) {
sh->restore_nodepath_selection(saved);
if (item) {
this->nodepath = sp_nodepath_new(desktop, item, (prefs_get_int_attribute("tools.nodes", "show_handles", 1) != 0));
if (this->nodepath) {
- this->nodepath->shape_editor = this;
+ this->nodepath->shape_editor = this;
}
this->knotholder = sp_item_knot_holder(item, desktop);
}
}
+/** Please note that this function only works for path parameters.
+* All other parameters probably will crash Inkscape!
+* Fortunately, there are no other on-canvas edittable objects at this moment :)
+*/
+void ShapeEditor::set_item_livepatheffect_parameter(SPItem *item, SPObject *lpeobject, const char * key) {
+
+ unset_item();
+
+ this->grab_node = -1;
+
+ if (lpeobject) {
+ this->knotholder = NULL; // it's a path, no special knotholder needed.
+ this->nodepath = sp_nodepath_new( desktop, lpeobject,
+ (prefs_get_int_attribute("tools.nodes", "show_handles", 1) != 0),
+ key, item);
+ if (this->nodepath) {
+ this->nodepath->shape_editor = this;
+
+ // setting new listener
+ Inkscape::XML::Node *repr = SP_OBJECT_REPR(lpeobject);
+ if (repr) {
+ Inkscape::GC::anchor(repr);
+ sp_repr_add_listener(repr, &shapeeditor_repr_events, this);
+ }
+ }
+ }
+}
+
+/** FIXME: think about this. Is this thing only called when the item needs to be updated?
+ Why not make a reload function in NodePath and in KnotHolder? */
+void ShapeEditor::reset_item ()
+{
+ if ( (this->nodepath) && (IS_LIVEPATHEFFECT(this->nodepath->object)) ) {
+ SPItem * item = this->nodepath->item;
+ SPObject *obj = this->nodepath->object;
+ char * key = g_strdup(this->nodepath->repr_key);
+ set_item_livepatheffect_parameter(item, obj, key);
+ g_free(key);
+ } else {
+ SPItem * item = get_item();
+ set_item(item);
+ }
+}
+
void ShapeEditor::nodepath_destroyed () {
this->nodepath = NULL;
}
bool ShapeEditor::is_over_stroke (NR::Point event_p, bool remember) {
- if (!this->nodepath)
+ if (!this->nodepath)
return false; // no stroke in knotholder
SPItem *item = get_item();
//Translate click point into proper coord system
this->curvepoint_doc = desktop->w2d(event_p);
this->curvepoint_doc *= sp_item_dt2i_affine(item);
- this->curvepoint_doc *= sp_item_i2doc_affine(item);
sp_nodepath_ensure_livarot_path(this->nodepath);
delta = desktop->d2w(delta);
double stroke_tolerance =
- (SP_OBJECT_STYLE (item)->stroke.type != SP_PAINT_TYPE_NONE?
- desktop->current_zoom() *
- SP_OBJECT_STYLE (item)->stroke_width.computed *
- sp_item_i2d_affine (item).expansion() * 0.5
+ (( !SP_OBJECT_STYLE(item)->stroke.isNone() ?
+ desktop->current_zoom() *
+ SP_OBJECT_STYLE (item)->stroke_width.computed * 0.5 *
+ sp_item_i2d_affine (item).expansion()
: 0.0)
- + prefs_get_int_attribute_limited("options.dragtolerance", "value", 0, 0, 100); //(double) SP_EVENT_CONTEXT(nc)->tolerance;
-
+ + prefs_get_int_attribute_limited("options.dragtolerance", "value", 0, 0, 100)) /sp_item_i2d_affine (item).expansion();
bool close = (NR::L2 (delta) < stroke_tolerance);
if (remember && close) {
void ShapeEditor::curve_drag(gdouble eventx, gdouble eventy) {
- if (this->nodepath) {
+ if (this->nodepath && !this->nodepath->straight_path) {
if (this->grab_node == -1) // don't know which segment to drag
return;
}
void ShapeEditor::add_node () {
- sp_node_selected_add_node(); // FIXME fix that function by removing nodepath_current lookup, and pass it this->nodepath instead (needs fixing verbs/buttons first)
+ sp_node_selected_add_node(this->nodepath);
}
void ShapeEditor::delete_nodes () {
- sp_node_selected_delete(); // FIXME fix that function by removing nodepath_current lookup, and pass it this->nodepath instead (needs fixing verbs/buttons first)
+ sp_node_selected_delete(this->nodepath);
}
void ShapeEditor::delete_nodes_preserving_shape () {
}
}
+void ShapeEditor::delete_segment () {
+ sp_node_selected_delete_segment(this->nodepath);
+}
+
void ShapeEditor::set_node_type(int type) {
- sp_node_selected_set_type((Inkscape::NodePath::NodeType) type); // FIXME fix that function by removing nodepath_current lookup, and pass it this->nodepath instead (needs fixing verbs/buttons first)
+ sp_node_selected_set_type(this->nodepath, (Inkscape::NodePath::NodeType) type);
}
void ShapeEditor::break_at_nodes() {
- sp_node_selected_break(); // FIXME fix that function by removing nodepath_current lookup, and pass it this->nodepath instead (needs fixing verbs/buttons first)
+ sp_node_selected_break(this->nodepath);
}
void ShapeEditor::join_nodes() {
- sp_node_selected_join(); // FIXME fix that function by removing nodepath_current lookup, and pass it this->nodepath instead (needs fixing verbs/buttons first)
+ sp_node_selected_join(this->nodepath);
+}
+
+void ShapeEditor::join_segments() {
+ sp_node_selected_join_segment(this->nodepath);
}
void ShapeEditor::duplicate_nodes() {
- sp_node_selected_duplicate(); // FIXME fix that function by removing nodepath_current lookup, and pass it this->nodepath instead (needs fixing verbs/buttons first)
+ sp_node_selected_duplicate(this->nodepath);
}
void ShapeEditor::set_type_of_segments(NRPathcode code) {
- sp_node_selected_set_line_type(code); // FIXME fix that function by removing nodepath_current lookup, and pass it this->nodepath instead (needs fixing verbs/buttons first)
+ sp_node_selected_set_line_type(this->nodepath, code);
}
void ShapeEditor::move_nodes_screen(gdouble dx, gdouble dy) {
- sp_node_selected_move_screen(dx, dy); // FIXME fix that function by removing nodepath_current lookup, and pass it this->nodepath instead (needs fixing verbs/buttons first)
+ sp_node_selected_move_screen(this->nodepath, dx, dy);
}
void ShapeEditor::move_nodes(gdouble dx, gdouble dy) {
- sp_node_selected_move(dx, dy); // FIXME fix that function by removing nodepath_current lookup, and pass it this->nodepath instead (needs fixing verbs/buttons first)
+ sp_node_selected_move(this->nodepath, dx, dy);
}
void ShapeEditor::rotate_nodes(gdouble angle, int which, bool screen) {
}
void ShapeEditor::select_all (bool invert) {
- if (this->nodepath)
+ if (this->nodepath)
sp_nodepath_select_all (this->nodepath, invert);
}
void ShapeEditor::select_all_from_subpath (bool invert) {
- if (this->nodepath)
+ if (this->nodepath)
sp_nodepath_select_all_from_subpath (this->nodepath, invert);
}
void ShapeEditor::select_next () {
- if (this->nodepath)
+ if (this->nodepath) {
sp_nodepath_select_next (this->nodepath);
+ if (this->nodepath->numSelected() >= 1) {
+ this->desktop->scroll_to_point(&(this->nodepath->singleSelectedCoords()), 1.0);
+ }
+ }
}
void ShapeEditor::select_prev () {
- if (this->nodepath)
+ if (this->nodepath) {
sp_nodepath_select_prev (this->nodepath);
+ if (this->nodepath->numSelected() >= 1) {
+ this->desktop->scroll_to_point(&(this->nodepath->singleSelectedCoords()), 1.0);
+ }
+ }
+}
+
+void ShapeEditor::show_handles (bool show) {
+ if (this->nodepath && !this->nodepath->straight_path)
+ sp_nodepath_show_handles (this->nodepath, show);
+}
+
+void ShapeEditor::show_helperpath (bool show) {
+ if (this->nodepath)
+ sp_nodepath_show_helperpath (this->nodepath, show);
}
void ShapeEditor::flip (NR::Dim2 axis, NR::Maybe<NR::Point> center) {
- if (this->nodepath)
+ if (this->nodepath)
sp_nodepath_flip (this->nodepath, axis, center);
}
void ShapeEditor::distribute (NR::Dim2 axis) {
- if (this->nodepath)
+ if (this->nodepath)
sp_nodepath_selected_distribute (this->nodepath, axis);
}
void ShapeEditor::align (NR::Dim2 axis) {
- if (this->nodepath)
+ if (this->nodepath)
sp_nodepath_selected_align (this->nodepath, axis);
}