From f2842c271819908b0ea5b61be57508ba76498fdb Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Date: Fri, 24 Dec 2021 19:57:44 +0100 Subject: [PATCH] ... --- src/object/sp-lpe-item.cpp | 101 ------------------------------------ src/object/sp-lpe-item.h | 4 -- src/selection-chemistry.cpp | 25 +++++---- src/seltrans.cpp | 82 ++++------------------------- src/seltrans.h | 1 - src/ui/clipboard.cpp | 21 +++++++- src/ui/clipboard.h | 7 ++- 7 files changed, 51 insertions(+), 190 deletions(-) diff --git a/src/object/sp-lpe-item.cpp b/src/object/sp-lpe-item.cpp index a4e4db8c34..1f1de2d2ec 100755 --- a/src/object/sp-lpe-item.cpp +++ b/src/object/sp-lpe-item.cpp @@ -1541,107 +1541,6 @@ bool SPLPEItem::pathEffectsEnabled() const return path_effects_enabled > 0; } -// 1.1 COPYPASTECLONESTAMPLPEBUG -bool SPLPEItem::autoFlattenFix() { - if (path_effect_list->empty()) { - return false; - } - for (PathEffectList::const_iterator it = path_effect_list->begin(); it != path_effect_list->end(); ++it) - { - LivePathEffectObject const *lpeobj = (*it)->lpeobject; - if (lpeobj) { - Inkscape::LivePathEffect::Effect const* lpe = lpeobj->get_lpe(); - if (lpe) { - Inkscape::LivePathEffect::LPECopyRotate const *rc = dynamic_cast(lpe); - Inkscape::LivePathEffect::LPEMirrorSymmetry const *ms = dynamic_cast(lpe); - Inkscape::LivePathEffect::LPESlice const *sl = dynamic_cast(lpe); - Inkscape::LivePathEffect::LPEBool const *bo = dynamic_cast(lpe); - if ((rc && rc->split_items) || (ms && ms->split_items)) { - return true; - } else if (sl || bo) { - return true; - } - } - } - } - return false; -} - -void SPLPEItem::removeAllAutoFlatten() -{ - cleanupAutoFlatten(); - if (autoFlattenFix()) { - sp_lpe_item_enable_path_effects(this, false); - } - SPGroup *group = dynamic_cast(this); - if (group) { - std::vector item_list = sp_item_group_item_list(group); - for (auto iter : item_list) { - SPLPEItem *subitem = dynamic_cast(iter); - if (subitem) { - subitem->removeAllAutoFlatten(); - } - } - } - if (autoFlattenFix()) { - SPDocument *doc = this->document; - gchar *id = g_strdup(this->getId()); - removeAllPathEffects(true); - if (doc) { - SPObject *newobj = doc->getObjectById(id); - SPLPEItem *newlpitem = dynamic_cast(newobj); - if (newlpitem && !newlpitem->path_effects_enabled) { - sp_lpe_item_enable_path_effects(newlpitem, true); - } - } - g_free(id); - } -} - -void SPLPEItem::cleanupAutoFlatten() -{ - SPGroup* group = dynamic_cast(this); - if (group) { - std::vector item_list = sp_item_group_item_list(group); - for (auto iter : item_list) { - SPLPEItem * subitem = dynamic_cast(iter); - if (subitem) { - subitem->cleanupAutoFlatten(); - } - } - } - Glib::ustring classes = "-slice"; - if (getAttribute("class")) { - Glib::ustring classupd = getAttribute("class"); - Glib::ustring finalclass = ""; - for (auto classindi : Glib::Regex::split_simple(" ", classupd)) { - size_t pos = classindi.find(classes); - if (pos == Glib::ustring::npos && classindi != "UnoptimicedTransforms") { - if (finalclass != "") { - finalclass += " "; - } - finalclass += classindi; - } - } - setAttribute("class", finalclass == "" ? nullptr : finalclass.c_str()); - } -} - -SPObject * sp_lpe_item_remove_autoflatten(SPItem *item, const gchar *id) { - SPObject *ret = dynamic_cast(item); - SPLPEItem *lpeitem = dynamic_cast(item); - if (lpeitem) { - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - prefs->setBool("/live_effects/flattening", true); - lpeitem->removeAllAutoFlatten(); - prefs->setBool("/live_effects/flattening", false); - // we want active document to use clipboard doc - ret = SP_ACTIVE_DOCUMENT->getObjectById(id); - } - return ret; -} -// END COPYPASTECLONESTAMPLPEBUG - /* Local Variables: mode:c++ diff --git a/src/object/sp-lpe-item.h b/src/object/sp-lpe-item.h index a4c0e8be71..08a79fce26 100644 --- a/src/object/sp-lpe-item.h +++ b/src/object/sp-lpe-item.h @@ -61,9 +61,6 @@ public: void update(SPCtx* ctx, unsigned int flags) override; void modified(unsigned int flags) override; - bool autoFlattenFix(); - void removeAllAutoFlatten(); - void cleanupAutoFlatten(); void child_added(Inkscape::XML::Node* child, Inkscape::XML::Node* ref) override; void remove_child(Inkscape::XML::Node* child) override; @@ -118,7 +115,6 @@ public: }; void sp_lpe_item_update_patheffect (SPLPEItem *lpeitem, bool wholetree, bool write); // careful, class already has method with *very* similar name! void sp_lpe_item_enable_path_effects(SPLPEItem *lpeitem, bool enable); -SPObject * sp_lpe_item_remove_autoflatten(SPItem *item, const gchar *id); MAKE_SP_OBJECT_DOWNCAST_FUNCTIONS(SP_LPE_ITEM, SPLPEItem) MAKE_SP_OBJECT_TYPECHECK_FUNCTIONS(SP_IS_LPE_ITEM, SPLPEItem) diff --git a/src/selection-chemistry.cpp b/src/selection-chemistry.cpp index c0d62dc713..4dc5f3e4bb 100644 --- a/src/selection-chemistry.cpp +++ b/src/selection-chemistry.cpp @@ -445,12 +445,25 @@ void ObjectSet::duplicate(bool suppressDone, bool duplicateLayer) //TODO: understand why layer management is tied to desktop and not to document. return; } - SPDocument *doc = document(); if(!doc) return; + if (!duplicateLayer && desktop()) { + Inkscape::UI::ClipboardManager *cm = Inkscape::UI::ClipboardManager::get(); + cm->setBackup(); + cm->copy(this); + if (cm->paste(desktop(), true)) { + if ( !suppressDone ) { + DocumentUndo::done(document(), _("Duplicate"), INKSCAPE_ICON("edit-duplicate")); + } + } + cm->restoreBackup(); + cm->emptyBackup(); + return; + } + Inkscape::XML::Document* xml_doc = doc->getReprDoc(); // check if something is selected @@ -494,15 +507,6 @@ void ObjectSet::duplicate(bool suppressDone, bool duplicateLayer) if (!duplicateLayer || sp_repr_is_def(old_repr)) { parent->appendChild(copy); - // 1.1 COPYPASTECLONESTAMPLPEBUG - SPItem *newitem = dynamic_cast(doc->getObjectByRepr(copy)); - if (_desktop && newitem) { - remove_hidder_filter(newitem); - gchar * id = strdup(copy->attribute("id")); - copy = sp_lpe_item_remove_autoflatten(newitem, id)->getRepr(); - g_free(id); - } - // END 1.1 COPYPASTECLONESTAMPLPEBUG fix } else if (sp_repr_is_layer(old_repr)) { parent->addChild(copy, old_repr); } else { @@ -617,6 +621,7 @@ void ObjectSet::duplicate(bool suppressDone, bool duplicateLayer) } } + void sp_edit_clear_all(Inkscape::Selection *selection) { if (!selection) diff --git a/src/seltrans.cpp b/src/seltrans.cpp index 841c6038ab..0d94bcbb8b 100644 --- a/src/seltrans.cpp +++ b/src/seltrans.cpp @@ -49,6 +49,7 @@ #include "object/sp-root.h" #include "ui/icon-names.h" +#include "ui/clipboard.h" #include "ui/modifiers.h" #include "ui/knot/knot.h" #include "ui/tools/select-tool.h" @@ -354,7 +355,6 @@ void Inkscape::SelTrans::grab(Geom::Point const &p, gdouble x, gdouble y, bool s } _updateHandles(); - g_return_if_fail(_stamp_cache.empty()); } void Inkscape::SelTrans::transform(Geom::Affine const &rel_affine, Geom::Point const &norm) @@ -446,9 +446,6 @@ void Inkscape::SelTrans::ungrab() for (auto & i : _l) i->hide(); } - if(!_stamp_cache.empty()){ - _stamp_cache.clear(); - } _message_context.clear(); @@ -529,76 +526,17 @@ void Inkscape::SelTrans::ungrab() void Inkscape::SelTrans::stamp() { Inkscape::Selection *selection = _desktop->getSelection(); - - bool fixup = !_grabbed; - if ( fixup && !_stamp_cache.empty() ) { - // TODO - give a proper fix. Simple temporary work-around for the grab() issue - _stamp_cache.clear(); - } - - /* stamping mode */ - if (!_empty) { - std::vector l; - if (!_stamp_cache.empty()) { - l = _stamp_cache; - } else { - /* Build cache */ - l.insert(l.end(), selection->items().begin(), selection->items().end()); - sort(l.begin(), l.end(), sp_object_compare_position_bool); - _stamp_cache = l; - } - - for(auto original_item : l) { - Inkscape::XML::Node *original_repr = original_item->getRepr(); - - // remember parent - Inkscape::XML::Node *parent = original_repr->parent(); - - Inkscape::XML::Node *copy_repr = original_repr->duplicate(parent->document()); - - // add the new repr to the parent - parent->addChild(copy_repr, original_repr->prev()); - - SPItem *copy_item = (SPItem *) _desktop->getDocument()->getObjectByRepr(copy_repr); - // 1.1 COPYPASTECLONESTAMPLPEBUG - SPItem *newitem = dynamic_cast(_desktop->getDocument()->getObjectByRepr(copy_repr)); - if (newitem) { - remove_hidder_filter(newitem); - gchar * id = strdup(copy_item->getId()); - copy_item = (SPItem *) sp_lpe_item_remove_autoflatten(newitem, id); - copy_repr = copy_item->getRepr(); - g_free(id); - } - // END COPYPASTECLONESTAMPLPEBUG - Geom::Affine const *new_affine; - if (_show == SHOW_OUTLINE) { - Geom::Affine const i2d(original_item->i2dt_affine()); - Geom::Affine const i2dnew( i2d * _current_relative_affine ); - copy_item->set_i2d_affine(i2dnew); - new_affine = ©_item->transform; - } else { - new_affine = &original_item->transform; - } - - copy_item->doWriteTransform(*new_affine); - - if ( copy_item->isCenterSet() && _center ) { - copy_item->setCenter(*_center * _current_relative_affine); - } - Inkscape::GC::release(copy_repr); - SPLPEItem * lpeitem = dynamic_cast(copy_item); - if(lpeitem && lpeitem->hasPathEffectRecursive()) { - lpeitem->forkPathEffectsIfNecessary(1); - sp_lpe_item_update_patheffect(lpeitem, true, true); - } - } + selection->setBackup(); + Inkscape::UI::ClipboardManager *cm = Inkscape::UI::ClipboardManager::get(); + cm->setBackup(); + cm->copy(selection); + if (cm->paste(_desktop, true)) { DocumentUndo::done(_desktop->getDocument(), _("Stamp"), INKSCAPE_ICON("tool-pointer")); } - - if ( fixup && !_stamp_cache.empty() ) { - // TODO - give a proper fix. Simple temporary work-around for the grab() issue - _stamp_cache.clear(); - } + cm->restoreBackup(); + cm->emptyBackup(); + selection->restoreBackup(); + selection->emptyBackup(); } void Inkscape::SelTrans::_updateHandles() diff --git a/src/seltrans.h b/src/seltrans.h index 1ed6945776..3158b1e41f 100644 --- a/src/seltrans.h +++ b/src/seltrans.h @@ -183,7 +183,6 @@ private: Inkscape::CanvasItemCtrl *_norm; Inkscape::CanvasItemCtrl *_grip; Inkscape::CanvasItemCurve *_l[4]; - std::vector _stamp_cache; Geom::Point _origin; ///< position of origin for transforms Geom::Point _point; ///< original position of the knot being used for the current transform diff --git a/src/ui/clipboard.cpp b/src/ui/clipboard.cpp index 70fc4d1627..155858fea2 100644 --- a/src/ui/clipboard.cpp +++ b/src/ui/clipboard.cpp @@ -103,6 +103,9 @@ namespace UI { class ClipboardManagerImpl : public ClipboardManager { public: void copy(ObjectSet *set) override; + void setBackup() override; + void restoreBackup() override; + void emptyBackup() override; void copyPathParameter(Inkscape::LivePathEffect::PathParam *) override; void copySymbol(Inkscape::XML::Node* symbol, gchar const* style, bool user_symbol) override; bool paste(SPDesktop *desktop, bool in_place) override; @@ -150,6 +153,7 @@ private: // private properites std::unique_ptr _clipboardSPDoc; ///< Document that stores the clipboard until someone requests it + std::unique_ptr _backup; ///< Document that stores the clipboard until someone requests it Inkscape::XML::Node *_defs; ///< Reference to the clipboard document's defs node Inkscape::XML::Node *_root; ///< Reference to the clipboard's root node Inkscape::XML::Node *_clipnode; ///< The node that holds extra information @@ -202,7 +206,9 @@ ClipboardManagerImpl::ClipboardManagerImpl() } -ClipboardManagerImpl::~ClipboardManagerImpl() = default; +ClipboardManagerImpl::~ClipboardManagerImpl() { + emptyBackup(); +}; /** @@ -1567,6 +1573,19 @@ void ClipboardManagerImpl::_createInternalClipboard() } } +void ClipboardManagerImpl::setBackup() { + std::swap(_backup,_clipboardSPDoc); +} + +void ClipboardManagerImpl::emptyBackup() { + if (_backup) { + delete _backup.release(); + } +} + +void ClipboardManagerImpl::restoreBackup() { + std::swap(_backup,_clipboardSPDoc); +} /** * Deletes the internal clipboard document. diff --git a/src/ui/clipboard.h b/src/ui/clipboard.h index 4815f52cd8..4b8568f90c 100644 --- a/src/ui/clipboard.h +++ b/src/ui/clipboard.h @@ -39,6 +39,9 @@ namespace UI { class ClipboardManager { public: virtual void copy(ObjectSet *set) = 0; + virtual void setBackup() = 0; + virtual void emptyBackup() = 0; + virtual void restoreBackup() = 0; virtual void copyPathParameter(Inkscape::LivePathEffect::PathParam *) = 0; virtual void copySymbol(Inkscape::XML::Node* symbol, gchar const* style, bool user_symbol = true) = 0; virtual bool paste(SPDesktop *desktop, bool in_place = false) = 0; @@ -50,14 +53,16 @@ public: virtual std::vector getElementsOfType(SPDesktop *desktop, gchar const* type = "*", gint maxdepth = -1) = 0; virtual Glib::ustring getFirstObjectID() = 0; static ClipboardManager *get(); + static ClipboardManager *getVolatil(); protected: ClipboardManager(); // singleton virtual ~ClipboardManager(); private: ClipboardManager(const ClipboardManager &) = delete; ///< no copy - ClipboardManager &operator=(const ClipboardManager &) = delete; ///< no assign + ClipboardManager &operator=(const ClipboardManager &) = delete; ///< no assign static ClipboardManager *_instance; + static ClipboardManager *_instance2; }; } // namespace IO -- GitLab