1
#define INKSCAPE_LIVEPATHEFFECT_PARAMETER_PATH_CPP
4
* Copyright (C) Johan Engelen 2007 <j.b.c.engelen@utwente.nl>
6
* Released under GNU GPL, read the file 'COPYING' for more information
9
#include "live_effects/parameter/path.h"
10
#include "live_effects/effect.h"
12
#include <2geom/svg-path-parser.h>
13
#include <2geom/sbasis-to-bezier.h>
14
#include <2geom/pathvector.h>
17
#include "ui/widget/point.h"
18
#include "widgets/icon.h"
19
#include <gtk/gtkstock.h>
20
#include "selection-chemistry.h"
24
#include "message-stack.h"
28
// needed for on-canvas editting:
29
#include "tools-switch.h"
30
#include "shape-editor.h"
31
#include "node-context.h"
32
#include "desktop-handles.h"
33
#include "selection.h"
36
#include "ui/clipboard.h"
37
// required for linking to other paths
41
#include "display/curve.h"
46
namespace LivePathEffect {
48
PathParam::PathParam( const Glib::ustring& label, const Glib::ustring& tip,
49
const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr,
50
Effect* effect, const gchar * default_value)
51
: Parameter(label, tip, key, wr, effect),
55
must_recalculate_pwd2(false),
57
ref( (SPObject*)effect->getLPEObj() )
59
defvalue = g_strdup(default_value);
60
param_readSVGValue(defvalue);
61
oncanvas_editable = true;
63
ref_changed_connection = ref.changedSignal().connect(sigc::mem_fun(*this, &PathParam::ref_changed));
66
PathParam::~PathParam()
73
std::vector<Geom::Path> const &
74
PathParam::get_pathvector()
79
Geom::Piecewise<Geom::D2<Geom::SBasis> > const &
87
PathParam::param_set_default()
89
param_readSVGValue(defvalue);
93
PathParam::param_set_and_write_default()
95
param_write_to_repr(defvalue);
99
PathParam::param_readSVGValue(const gchar * strvalue)
104
must_recalculate_pwd2 = true;
106
if (strvalue[0] == '#') {
109
href = g_strdup(strvalue);
111
// Now do the attaching, which emits the changed signal.
113
ref.attach(Inkscape::URI(href));
114
} catch (Inkscape::BadURIException &e) {
115
g_warning("%s", e.what());
117
_pathvector = sp_svg_read_pathv(defvalue);
120
_pathvector = sp_svg_read_pathv(strvalue);
131
PathParam::param_getSVGValue() const
136
gchar * svgd = sp_svg_write_path( _pathvector );
142
PathParam::param_newWidget(Gtk::Tooltips * tooltips)
144
Gtk::HBox * _widget = Gtk::manage(new Gtk::HBox());
146
Gtk::Label* pLabel = Gtk::manage(new Gtk::Label(param_label));
147
static_cast<Gtk::HBox*>(_widget)->pack_start(*pLabel, true, true);
148
tooltips->set_tip(*pLabel, param_tooltip);
150
Gtk::Widget* pIcon = Gtk::manage( sp_icon_get_icon( "tool-node-editor", Inkscape::ICON_SIZE_BUTTON) );
151
Gtk::Button * pButton = Gtk::manage(new Gtk::Button());
152
pButton->set_relief(Gtk::RELIEF_NONE);
154
pButton->add(*pIcon);
156
pButton->signal_clicked().connect(sigc::mem_fun(*this, &PathParam::on_edit_button_click));
157
static_cast<Gtk::HBox*>(_widget)->pack_start(*pButton, true, true);
158
tooltips->set_tip(*pButton, _("Edit on-canvas"));
160
pIcon = Gtk::manage( sp_icon_get_icon( GTK_STOCK_COPY, Inkscape::ICON_SIZE_BUTTON) );
161
pButton = Gtk::manage(new Gtk::Button());
162
pButton->set_relief(Gtk::RELIEF_NONE);
164
pButton->add(*pIcon);
166
pButton->signal_clicked().connect(sigc::mem_fun(*this, &PathParam::on_copy_button_click));
167
static_cast<Gtk::HBox*>(_widget)->pack_start(*pButton, true, true);
168
tooltips->set_tip(*pButton, _("Copy path"));
170
pIcon = Gtk::manage( sp_icon_get_icon( GTK_STOCK_PASTE, Inkscape::ICON_SIZE_BUTTON) );
171
pButton = Gtk::manage(new Gtk::Button());
172
pButton->set_relief(Gtk::RELIEF_NONE);
174
pButton->add(*pIcon);
176
pButton->signal_clicked().connect(sigc::mem_fun(*this, &PathParam::on_paste_button_click));
177
static_cast<Gtk::HBox*>(_widget)->pack_start(*pButton, true, true);
178
tooltips->set_tip(*pButton, _("Paste path"));
180
pIcon = Gtk::manage( sp_icon_get_icon( "edit-clone", Inkscape::ICON_SIZE_BUTTON) );
181
pButton = Gtk::manage(new Gtk::Button());
182
pButton->set_relief(Gtk::RELIEF_NONE);
184
pButton->add(*pIcon);
186
pButton->signal_clicked().connect(sigc::mem_fun(*this, &PathParam::on_link_button_click));
187
static_cast<Gtk::HBox*>(_widget)->pack_start(*pButton, true, true);
188
tooltips->set_tip(*pButton, _("Link to path"));
190
static_cast<Gtk::HBox*>(_widget)->show_all_children();
192
return dynamic_cast<Gtk::Widget *> (_widget);
196
PathParam::param_editOncanvas(SPItem * item, SPDesktop * dt)
198
// If not already in nodecontext, goto it!
199
if (!tools_isactive(dt, TOOLS_NODES)) {
200
tools_switch(dt, TOOLS_NODES);
203
ShapeEditor * shape_editor = dt->event_context->shape_editor;
205
shape_editor->set_item_lpe_path_parameter(item, param_effect->getLPEObj(), param_key.c_str());
207
// set referred item for editing
208
shape_editor->set_item(ref.getObject(), SH_NODEPATH);
213
PathParam::param_setup_nodepath(Inkscape::NodePath::Path *np)
215
np->show_helperpath = true;
216
np->helperpath_rgba = 0x009000ff;
217
np->helperpath_width = 1.0;
221
PathParam::addCanvasIndicators(SPLPEItem */*lpeitem*/, std::vector<Geom::PathVector> &hp_vec)
223
hp_vec.push_back(_pathvector);
227
* Only applies transform when not referring to other path!
230
PathParam::param_transform_multiply(Geom::Matrix const& postmul, bool /*set*/)
232
// only apply transform when not referring to other path
234
set_new_value( _pathvector * postmul, true );
239
* See comments for set_new_value(std::vector<Geom::Path>).
242
PathParam::set_new_value (Geom::Piecewise<Geom::D2<Geom::SBasis> > const & newpath, bool write_to_svg)
245
_pathvector = Geom::path_from_piecewise(newpath, LPE_CONVERSION_TOLERANCE);
248
gchar * svgd = sp_svg_write_path( _pathvector );
249
param_write_to_repr(svgd);
252
// After the whole "writing to svg avalanche of function calling": force value upon pwd2 and don't recalculate.
254
must_recalculate_pwd2 = false;
257
must_recalculate_pwd2 = false;
263
* This method sets new path data.
264
* If this PathParam refers to another path, this link is removed (and replaced with explicit path data).
266
* If write_to_svg = true :
267
* The new path data is written to SVG. In this case the signal_path_changed signal
268
* is not directly emited in this method, because writing to SVG
269
* triggers the LPEObject to which this belongs to call Effect::setParameter which calls
270
* PathParam::readSVGValue, which finally emits the signal_path_changed signal.
271
* If write_to_svg = false :
272
* The new path data is not written to SVG. This method will emit the signal_path_changed signal.
275
PathParam::set_new_value (std::vector<Geom::Path> const &newpath, bool write_to_svg)
278
_pathvector = newpath;
279
must_recalculate_pwd2 = true;
282
gchar * svgd = sp_svg_write_path( _pathvector );
283
param_write_to_repr(svgd);
291
PathParam::ensure_pwd2()
293
if (must_recalculate_pwd2) {
295
for (unsigned int i=0; i < _pathvector.size(); i++) {
296
_pwd2.concat( _pathvector[i].toPwSb() );
299
must_recalculate_pwd2 = false;
304
PathParam::emit_changed()
307
signal_path_changed.emit();
311
PathParam::start_listening(SPObject * to)
316
linked_delete_connection = to->connectDelete(sigc::mem_fun(*this, &PathParam::linked_delete));
317
linked_modified_connection = to->connectModified(sigc::mem_fun(*this, &PathParam::linked_modified));
318
linked_modified(to, SP_OBJECT_MODIFIED_FLAG); // simulate linked_modified signal, so that path data is updated
322
PathParam::quit_listening(void)
324
linked_modified_connection.disconnect();
325
linked_delete_connection.disconnect();
329
PathParam::ref_changed(SPObject */*old_ref*/, SPObject *new_ref)
333
start_listening(new_ref);
338
PathParam::remove_link()
348
PathParam::linked_delete(SPObject */*deleted*/)
352
set_new_value (_pathvector, true);
356
PathParam::linked_modified(SPObject *linked_obj, guint /*flags*/)
358
SPCurve *curve = NULL;
359
if (SP_IS_SHAPE(linked_obj)) {
360
curve = sp_shape_get_curve(SP_SHAPE(linked_obj));
362
if (SP_IS_TEXT(linked_obj)) {
363
curve = SP_TEXT(linked_obj)->getNormalizedBpath();
367
// curve invalid, set default value
368
_pathvector = sp_svg_read_pathv(defvalue);
370
_pathvector = curve->get_pathvector();
374
must_recalculate_pwd2 = true;
376
SP_OBJECT(param_effect->getLPEObj())->requestModified(SP_OBJECT_MODIFIED_FLAG);
379
/* CALLBACK FUNCTIONS FOR THE BUTTONS */
381
PathParam::on_edit_button_click()
383
SPItem * item = sp_desktop_selection(SP_ACTIVE_DESKTOP)->singleItem();
385
param_editOncanvas(item, SP_ACTIVE_DESKTOP);
390
PathParam::paste_param_path(const char *svgd)
392
// only recognize a non-null, non-empty string
394
// remove possible link to path
397
param_write_to_repr(svgd);
398
signal_path_pasted.emit();
403
PathParam::on_paste_button_click()
405
Inkscape::UI::ClipboardManager *cm = Inkscape::UI::ClipboardManager::get();
406
Glib::ustring svgd = cm->getPathParameter();
407
paste_param_path(svgd.data());
408
sp_document_done(param_effect->getSPDoc(), SP_VERB_DIALOG_LIVE_PATH_EFFECT,
409
_("Paste path parameter"));
413
PathParam::on_copy_button_click()
415
Inkscape::UI::ClipboardManager *cm = Inkscape::UI::ClipboardManager::get();
416
cm->copyPathParameter(this);
420
PathParam::on_link_button_click()
422
Inkscape::UI::ClipboardManager *cm = Inkscape::UI::ClipboardManager::get();
423
Glib::ustring pathid = cm->getShapeOrTextObjectId();
429
// add '#' at start to make it an uri.
430
pathid.insert(pathid.begin(), '#');
431
if ( href && strcmp(pathid.c_str(), href) == 0 ) {
432
// no change, do nothing
436
// check if id really exists in document, or only in clipboard document: if only in clipboard then invalid
437
// check if linking to object to which LPE is applied (maybe delegated to PathReference
439
param_write_to_repr(pathid.c_str());
440
sp_document_done(param_effect->getSPDoc(), SP_VERB_DIALOG_LIVE_PATH_EFFECT,
441
_("Link path parameter to path"));
445
} /* namespace LivePathEffect */
447
} /* namespace Inkscape */
452
c-file-style:"stroustrup"
453
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
458
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :