Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
satellite.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * Copyright (C) Johan Engelen 2007 <j.b.c.engelen@utwente.nl>
4 * Abhishek Sharma
5 *
6 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
7 */
8
10
11#include <glibmm/i18n.h>
12#include <gtkmm/box.h>
13#include <gtkmm/button.h>
14#include <gtkmm/image.h>
15#include <gtkmm/label.h>
16
17#include "bad-uri-exception.h"
18#include "inkscape.h"
19
20#include "live_effects/effect.h"
22#include "object/sp-item.h"
23#include "object/uri.h"
24#include "ui/clipboard.h"
25#include "ui/icon-loader.h"
26#include "ui/pack.h"
27
28namespace Inkscape {
29namespace LivePathEffect {
30
31SatelliteParam::SatelliteParam(const Glib::ustring &label, const Glib::ustring &tip, const Glib::ustring &key,
33 : Parameter(label, tip, key, wr, effect)
34 , lperef(std::make_shared<SatelliteReference>(param_effect->getLPEObj(), false))
35 , last_transform(Geom::identity())
36{}
37
41
42std::vector<SPObject *> SatelliteParam::param_get_satellites()
43{
44 std::vector<SPObject *> objs;
45 // we reload connexions in case are lost for example item recreation on ungroup
48 }
49
50 SPObject * linked_obj = lperef->getObject();
51 if (linked_obj) {
52 objs.push_back(linked_obj);
53 }
54 return objs;
55}
56
57bool SatelliteParam::param_readSVGValue(char const *strvalue)
58{
59 if (strvalue && strvalue[0] == '#' && lperef->getObject() && std::strcmp(strvalue + 1, lperef->getObject()->getId()) == 0) {
60 return false;
61 }
62
63 if (strvalue) {
64 bool write = false;
65 auto lpeitems = param_effect->getCurrrentLPEItems();
66 Glib::ustring id_tmp;
67 if (lpeitems.empty() && !param_effect->is_applied && !param_effect->getSPDoc()->isSeeking()) {
68 SPObject * old_ref = param_effect->getSPDoc()->getObjectByHref(strvalue);
69 if (old_ref) {
70 SPObject * tmpsuccessor = old_ref->_tmpsuccessor;
71 // cast to effect is not possible now
72 if (!g_strcmp0("clone_original", param_effect->getLPEObj()->getAttribute("effect"))) {
73 id_tmp = strvalue;
74 }
75 if (tmpsuccessor && tmpsuccessor->getId()) {
76 id_tmp = tmpsuccessor->getId();
77 id_tmp.insert(id_tmp.begin(), '#');
78 write = true;
79 }
80 strvalue = id_tmp.c_str();
81 }
82 }
83 SPObject *old_ref = lperef->getObject();
84 if (old_ref) {
85 unlink();
86 }
87 if (strvalue[0] == '#') {
88 try {
89 lperef->attach(Inkscape::URI(strvalue));
90 // lp:1299948
91 SPObject *new_ref = lperef->getObject();
92 if (new_ref) {
93 linked_changed(old_ref, new_ref);
94 // linked_modified(new_ref, SP_OBJECT_STYLESHEET_MODIFIED_FLAG);
95 } // else: document still processing new events. Repr of the linked object not created yet.
96 } catch (Inkscape::BadURIException &e) {
97 g_warning("%s", e.what());
98 lperef->detach();
99 }
100 } else if (lpeitems.empty() && !param_effect->is_applied && !param_effect->getSPDoc()->isSeeking()) {
102 }
103 if (write) {
105 }
106 return true;
107 }
108
109 return false;
110}
111
113{
114 return lperef->isAttached();
115}
116
118{
119 return lperef->isAttached() ? lperef->getObject() : nullptr;
120}
121
123{
124 if (lperef->getURI()) {
125 return lperef->getURI()->str();
126 }
127 return "";
128}
129
131{
132 return "";
133}
134
139
141{
143 if (linksToItem()) {
144 lperef->detach();
145 }
146}
147
148void SatelliteParam::link(Glib::ustring itemid)
149{
150 if (itemid.empty()) {
151 return;
152 }
153 auto *document = param_effect->getSPDoc();
154 SPObject *object = document->getObjectById(itemid);
155 if (object && object != getObject()) {
156 itemid.insert(itemid.begin(), '#');
157 param_write_to_repr(itemid.c_str());
158 } else {
160 }
161 param_effect->makeUndoDone(_("Link item parameter to path"));
162}
163
164// SIGNALS
165
167{
168 if (!to) {
169 return;
170 }
172 linked_changed_connection = lperef->changedSignal().connect(sigc::mem_fun(*this, &SatelliteParam::linked_changed));
173 auto item = cast<SPItem>(to);
174 if (item) {
179 if (!param_effect->is_load) {
180 linked_modified(item, SP_OBJECT_MODIFIED_FLAG);
181 }
182 }
183}
184
186{
188 linked_changed_connection.disconnect();
189 }
191 linked_released_connection.disconnect();
192 }
194 linked_modified_connection.disconnect();
195 }
198 }
199}
200
202{
204 if (new_obj) {
205 start_listening(new_obj);
206 }
207}
208
216
217
218void SatelliteParam::linked_modified(SPObject *linked_obj, guint flags)
219{
220 if (!_updating && flags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG |
221 SP_OBJECT_CHILD_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG)) {
222 if (!param_effect->is_load || ownerlocator || (!SP_ACTIVE_DESKTOP && param_effect->isReady())) {
223 param_effect->getLPEObj()->requestModified(SP_OBJECT_MODIFIED_FLAG);
224 }
226 if (effectType() != CLONE_ORIGINAL) {
228 }
229 }
230}
231
232void SatelliteParam::linked_transformed(Geom::Affine const *rel_transf, SPItem *moved_item)
233{
234 if (!_updating) {
236 }
237}
238
239// UI
240
241void SatelliteParam::addCanvasIndicators(SPLPEItem const * /*lpeitem*/, std::vector<Geom::PathVector> &hp_vec) {}
242
244{
246 // here prevent item is reseted transform on link
247 if (effectType() == CLONE_ORIGINAL) {
248 param_effect->is_load = false;
249 }
250 Glib::ustring itemid;
251 if (lookup) {
252 std::vector<Glib::ustring> clones = cm->getElementsOfType(nullptr, "svg:use", 2);
253 if (!clones.empty()) {
254 itemid = clones[0];
255 }
256 }
257 if (itemid.empty()) {
258 itemid = cm->getFirstObjectID();
259 }
260 if (itemid.empty()) {
261 return;
262 }
263
264 link(itemid);
265}
266
268{
269 auto const _widget = Gtk::make_managed<Gtk::Box>(Gtk::Orientation::HORIZONTAL);
270 Gtk::Image *pIcon = Gtk::manage(sp_get_icon_image("edit-clone", Gtk::IconSize::NORMAL));
271 auto const pButton = Gtk::make_managed<Gtk::Button>();
272 auto const pLabel = Gtk::make_managed<Gtk::Label>(param_label);
273 UI::pack_start(*_widget, *pLabel, true, true);
274 pLabel->set_tooltip_text(param_tooltip);
275 pButton->set_has_frame(false);
276 pButton->set_child(*pIcon);
277 pButton->signal_clicked().connect(sigc::mem_fun(*this, &SatelliteParam::on_link_button_click));
278 UI::pack_start(*_widget, *pButton, true, true);
279 pButton->set_tooltip_text(_("Link to item on clipboard"));
280
281 return _widget;
282}
283
284} /* namespace LivePathEffect */
285} /* namespace Inkscape */
286
287/*
288 Local Variables:
289 mode:c++
290 c-file-style:"stroustrup"
291 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
292 indent-tabs-mode:nil
293 fill-column:99
294 End:
295*/
296// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :
TODO: insert short description here.
3x3 matrix representing an affine transformation.
Definition affine.h:70
virtual void processObjects(LPEAction lpe_action)
Definition effect.cpp:1416
std::vector< SPLPEItem * > getCurrrentLPEItems() const
Definition effect.cpp:1187
void makeUndoDone(Glib::ustring message)
Definition effect.cpp:1521
LivePathEffectObject * getLPEObj()
Definition effect.h:150
Inkscape::Display::TemporaryItem * ownerlocator
Definition parameter.h:111
void param_write_to_repr(const char *svgd)
Definition parameter.cpp:52
bool param_readSVGValue(const gchar *strvalue) override
Definition satellite.cpp:57
std::vector< SPObject * > param_get_satellites() override
Definition satellite.cpp:42
void link(Glib::ustring itemid)
sigc::connection linked_transformed_connection
Definition satellite.h:64
Glib::ustring param_getSVGValue() const override
void linked_modified(SPObject *linked_obj, guint flags)
Glib::ustring param_getDefaultSVGValue() const override
void linked_changed(SPObject *old_obj, SPObject *new_obj)
std::shared_ptr< SatelliteReference > lperef
Definition satellite.h:58
SatelliteParam(const Glib::ustring &label, const Glib::ustring &tip, const Glib::ustring &key, Inkscape::UI::Widget::Registry *wr, Effect *effect)
Definition satellite.cpp:31
void linked_released(SPObject *released_item)
void linked_transformed(Geom::Affine const *rel_transf, SPItem *moved_item)
void addCanvasIndicators(SPLPEItem const *lpeitem, std::vector< Geom::PathVector > &hp_vec) override
Gtk::Widget * param_newWidget() override
System-wide clipboard manager.
Definition clipboard.h:44
virtual std::vector< Glib::ustring > getElementsOfType(SPDesktop *desktop, gchar const *type="*", gint maxdepth=-1)=0
static ClipboardManager * get()
virtual Glib::ustring getFirstObjectID()=0
Represents an URI as per RFC 2396.
Definition uri.h:36
bool isSeeking() const
Definition document.h:359
SPObject * getObjectByHref(std::string const &href) const
Base class for visual SVG elements.
Definition sp-item.h:109
sigc::connection connectTransformed(sigc::slot< void(Geom::Affine const *, SPItem *)> slot)
Definition sp-item.h:234
SPObject is an abstract base class of all of the document nodes at the SVG document level.
Definition sp-object.h:160
void requestModified(unsigned int flags)
Requests that a modification notification signal be emitted later (e.g.
SPObject * _tmpsuccessor
Definition sp-object.h:731
char const * getId() const
Returns the objects current ID string.
sigc::connection connectRelease(sigc::slot< void(SPObject *)> slot)
Connects to the release request signal.
Definition sp-object.h:237
char const * getAttribute(char const *name) const
sigc::connection connectModified(sigc::slot< void(SPObject *, unsigned int)> slot)
Connects to the modification notification signal.
Definition sp-object.h:705
System-wide clipboard management - class declaration.
Gtk::Image * sp_get_icon_image(Glib::ustring const &icon_name, int size)
Icon Loader.
SPItem * item
Glib::ustring label
Various utility functions.
Definition affine.h:22
Affine identity()
Create an identity matrix.
Definition affine.h:210
void pack_start(Gtk::Box &box, Gtk::Widget &child, bool const expand, bool const fill, unsigned const padding)
Adds child to box, packed with reference to the start of box.
Definition pack.cpp:141
Helper class to stream background task notifications as a series of messages.
STL namespace.
static cairo_user_data_key_t key
Helpers for using Gtk::Boxes, encapsulating large changes between GTK3 & GTK4.
Some things pertinent to all visible shapes: SPItem, SPItemView, SPItemCtx.