void LivePathEffectEditor::onApply() { Inkscape::Selection *sel = _getSelection(); if ( sel && !sel->isEmpty() ) { SPItem *item = sel->singleItem(); if ( item && SP_IS_LPE_ITEM(item) ) { SPDocument *doc = current_desktop->doc(); const Util::EnumData<LivePathEffect::EffectType>* data = combo_effecttype.get_active_data(); if (!data) return; // If item is a SPRect, convert it to path first: if ( SP_IS_RECT(item) ) { sp_selected_path_to_curves(current_desktop, false); item = sel->singleItem(); // get new item } LivePathEffect::Effect::createAndApply(data->key.c_str(), doc, item); sp_document_done(doc, SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Create and apply path effect")); lpe_list_locked = false; onSelectionChanged(sel); } } }
static void sp_lpe_item_create_original_path_recursive(SPLPEItem *lpeitem) { g_return_if_fail(lpeitem != NULL); SPMask * mask = lpeitem->mask_ref->getObject(); if(mask) { sp_lpe_item_create_original_path_recursive(SP_LPE_ITEM(mask->firstChild())); } SPClipPath * clipPath = lpeitem->clip_ref->getObject(); if(clipPath) { sp_lpe_item_create_original_path_recursive(SP_LPE_ITEM(clipPath->firstChild())); } if (SP_IS_GROUP(lpeitem)) { GSList const *item_list = sp_item_group_item_list(SP_GROUP(lpeitem)); for ( GSList const *iter = item_list; iter; iter = iter->next ) { SPObject *subitem = static_cast<SPObject *>(iter->data); if (SP_IS_LPE_ITEM(subitem)) { sp_lpe_item_create_original_path_recursive(SP_LPE_ITEM(subitem)); } } } else if (SP_IS_PATH(lpeitem)) { Inkscape::XML::Node *pathrepr = lpeitem->getRepr(); if ( !pathrepr->attribute("inkscape:original-d") ) { pathrepr->setAttribute("inkscape:original-d", pathrepr->attribute("d")); } } }
KnotHolder *createKnotHolder(SPItem *item, SPDesktop *desktop) { KnotHolder *knotholder = NULL; if (SP_IS_LPE_ITEM(item) && SP_LPE_ITEM(item)->getCurrentLPE() && SP_LPE_ITEM(item)->getCurrentLPE()->isVisible() && SP_LPE_ITEM(item)->getCurrentLPE()->providesKnotholder()) { knotholder = sp_lpe_knot_holder(item, desktop); } else if (SP_IS_RECT(item)) { knotholder = new RectKnotHolder(desktop, item, NULL); } else if (SP_IS_BOX3D(item)) { knotholder = new Box3DKnotHolder(desktop, item, NULL); } else if (SP_IS_GENERICELLIPSE(item)) { knotholder = new ArcKnotHolder(desktop, item, NULL); } else if (SP_IS_STAR(item)) { knotholder = new StarKnotHolder(desktop, item, NULL); } else if (SP_IS_SPIRAL(item)) { knotholder = new SpiralKnotHolder(desktop, item, NULL); } else if (SP_IS_OFFSET(item)) { knotholder = new OffsetKnotHolder(desktop, item, NULL); } else if (SP_IS_FLOWTEXT(item) && SP_FLOWTEXT(item)->has_internal_frame()) { knotholder = new FlowtextKnotHolder(desktop, SP_FLOWTEXT(item)->get_frame(NULL), NULL); } else if ((item->style->fill.isPaintserver()) && SP_IS_PATTERN(item->style->getFillPaintServer())) { knotholder = new KnotHolder(desktop, item, NULL); knotholder->add_pattern_knotholder(); } return knotholder; }
static gchar * sp_path_description(SPItem * item) { int count = SP_PATH(item)->nodesInPath(); if (SP_IS_LPE_ITEM(item) && sp_lpe_item_has_path_effect(SP_LPE_ITEM(item))) { Glib::ustring s; PathEffectList effect_list = sp_lpe_item_get_effect_list(SP_LPE_ITEM(item)); for (PathEffectList::iterator it = effect_list.begin(); it != effect_list.end(); ++it) { LivePathEffectObject *lpeobj = (*it)->lpeobject; if (!lpeobj || !lpeobj->get_lpe()) break; if (s.empty()) s = lpeobj->get_lpe()->getName(); else s = s + ", " + lpeobj->get_lpe()->getName(); } return g_strdup_printf(ngettext("<b>Path</b> (%i node, path effect: %s)", "<b>Path</b> (%i nodes, path effect: %s)",count), count, s.c_str()); } else { return g_strdup_printf(ngettext("<b>Path</b> (%i node)", "<b>Path</b> (%i nodes)",count), count); } }
bool SPLPEItem::hasPathEffectRecursive() const { if (parent && SP_IS_LPE_ITEM(parent)) { return hasPathEffect() || SP_LPE_ITEM(parent)->hasPathEffectRecursive(); } else { return hasPathEffect(); } }
void SPLPEItem::remove_child(Inkscape::XML::Node * child) { if (this->hasPathEffectRecursive()) { SPObject *ochild = this->get_child_by_repr(child); if ( ochild && SP_IS_LPE_ITEM(ochild) ) { sp_lpe_item_cleanup_original_path_recursive(SP_LPE_ITEM(ochild)); } } SPItem::remove_child(child); }
void SPLPEItem::child_added(Inkscape::XML::Node *child, Inkscape::XML::Node *ref) { SPItem::child_added(child, ref); if (this->hasPathEffectRecursive()) { SPObject *ochild = this->get_child_by_repr(child); if ( ochild && SP_IS_LPE_ITEM(ochild) ) { sp_lpe_item_create_original_path_recursive(SP_LPE_ITEM(ochild)); } } }
void LivePathEffectEditor::onSelectionChanged(Inkscape::Selection *sel) { if (lpe_list_locked) { // this was triggered by selecting a row in the list, so skip reloading lpe_list_locked = false; return; } effectlist_store->clear(); current_lpeitem = NULL; if ( sel && !sel->isEmpty() ) { SPItem *item = sel->singleItem(); if ( item ) { if ( SP_IS_LPE_ITEM(item) ) { SPLPEItem *lpeitem = SP_LPE_ITEM(item); effect_list_reload(lpeitem); current_lpeitem = lpeitem; set_sensitize_all(true); if ( sp_lpe_item_has_path_effect(lpeitem) ) { Inkscape::LivePathEffect::Effect *lpe = sp_lpe_item_get_current_lpe(lpeitem); if (lpe) { showParams(*lpe); lpe_list_locked = true; selectInList(lpe); } else { showText(_("Unknown effect is applied")); } } else { showText(_("No effect applied")); button_remove.set_sensitive(false); } } else { showText(_("Item is not a path or shape")); set_sensitize_all(false); } } else { showText(_("Only one item can be selected")); set_sensitize_all(false); } } else { showText(_("Empty selection")); set_sensitize_all(false); } }
void LivePathEffectEditor::onDown() { Inkscape::Selection *sel = _getSelection(); if ( sel && !sel->isEmpty() ) { SPItem *item = sel->singleItem(); if ( item && SP_IS_LPE_ITEM(item) ) { sp_lpe_item_down_current_path_effect(SP_LPE_ITEM(item)); sp_document_done ( sp_desktop_document (current_desktop), SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Move path effect down") ); effect_list_reload(SP_LPE_ITEM(item)); } } }
/** * Calls any registered handlers for the update_patheffect action */ void sp_lpe_item_update_patheffect (SPLPEItem *lpeitem, bool wholetree, bool write) { #ifdef SHAPE_VERBOSE g_message("sp_lpe_item_update_patheffect: %p\n", lpeitem); #endif g_return_if_fail (lpeitem != NULL); g_return_if_fail (SP_IS_LPE_ITEM (lpeitem)); if (!lpeitem->pathEffectsEnabled()) return; // TODO: hack! this will be removed when path length measuring is reimplemented in a better way PathEffectList lpelist = lpeitem->getEffectList(); std::list<Inkscape::LivePathEffect::LPEObjectReference *>::iterator i; for (i = lpelist.begin(); i != lpelist.end(); ++i) { if ((*i)->lpeobject) { Inkscape::LivePathEffect::Effect *lpe = (*i)->lpeobject->get_lpe(); if (dynamic_cast<Inkscape::LivePathEffect::LPEPathLength *>(lpe)) { if (!lpe->isVisible()) { // we manually disable text for LPEPathLength // use static_cast, because we already checked for the right type above static_cast<Inkscape::LivePathEffect::LPEPathLength *>(lpe)->hideCanvasText(); } } } } SPLPEItem *top = NULL; if (wholetree) { SPLPEItem *prev_parent = lpeitem; SPLPEItem *parent = dynamic_cast<SPLPEItem*>(prev_parent->parent); while (parent && parent->hasPathEffectRecursive()) { prev_parent = parent; parent = dynamic_cast<SPLPEItem*>(prev_parent->parent); } top = prev_parent; } else { top = lpeitem; } top->update_patheffect(write); }
bool sp_item_list_to_curves(const GSList *items, GSList **selected, GSList **to_select, bool skip_all_lpeitems) { bool did = false; for (; items != NULL; items = items->next) { SPItem *item = SP_ITEM(items->data); SPDocument *document = item->document; if ( skip_all_lpeitems && SP_IS_LPE_ITEM(item) && !SP_IS_GROUP(item) ) // also convert objects in an SPGroup when skip_all_lpeitems is set. { continue; } if (SP_IS_PATH(item) && !SP_PATH(item)->original_curve) { continue; // already a path, and no path effect } if (SP_IS_BOX3D(item)) { // convert 3D box to ordinary group of paths; replace the old element in 'selected' with the new group Inkscape::XML::Node *repr = SP_OBJECT_REPR(box3d_convert_to_group(SP_BOX3D(item))); if (repr) { *to_select = g_slist_prepend (*to_select, repr); did = true; *selected = g_slist_remove (*selected, item); } continue; } if (SP_IS_GROUP(item)) { sp_lpe_item_remove_all_path_effects(SP_LPE_ITEM(item), true); GSList *item_list = sp_item_group_item_list(SP_GROUP(item)); GSList *item_to_select = NULL; GSList *item_selected = NULL; if (sp_item_list_to_curves(item_list, &item_selected, &item_to_select)) did = true; g_slist_free(item_list); g_slist_free(item_to_select); g_slist_free(item_selected); continue; } Inkscape::XML::Node *repr = sp_selected_item_to_curved_repr(item, 0); if (!repr) continue; did = true; *selected = g_slist_remove (*selected, item); // remember the position of the item gint pos = SP_OBJECT_REPR(item)->position(); // remember parent Inkscape::XML::Node *parent = SP_OBJECT_REPR(item)->parent(); // remember id char const *id = SP_OBJECT_REPR(item)->attribute("id"); // remember title gchar *title = item->title(); // remember description gchar *desc = item->desc(); // It's going to resurrect, so we delete without notifying listeners. SP_OBJECT(item)->deleteObject(false); // restore id repr->setAttribute("id", id); // add the new repr to the parent parent->appendChild(repr); SPObject* newObj = document->getObjectByRepr(repr); if (title && newObj) { newObj->setTitle(title); g_free(title); } if (desc && newObj) { newObj->setDesc(desc); g_free(desc); } // move to the saved position repr->setPosition(pos > 0 ? pos : 0); /* Buglet: We don't re-add the (new version of the) object to the selection of any other * desktops where it was previously selected. */ *to_select = g_slist_prepend (*to_select, repr); Inkscape::GC::release(repr); } return did; }