diff options
| author | Jabiertxof <jtx@jtx> | 2016-12-16 22:44:26 +0000 |
|---|---|---|
| committer | Jabiertxof <jtx@jtx> | 2016-12-16 22:44:26 +0000 |
| commit | 8ce90cc9aeecfd5133926156f23ac3cbe318c49d (patch) | |
| tree | f0ecbf4a9e6717e11a1a88e12f0ae9b82ef62df0 /src | |
| parent | Update to trunk (diff) | |
| download | inkscape-8ce90cc9aeecfd5133926156f23ac3cbe318c49d.tar.gz inkscape-8ce90cc9aeecfd5133926156f23ac3cbe318c49d.zip | |
working with mirrors
(bzr r15295.1.24)
Diffstat (limited to 'src')
| -rw-r--r-- | src/live_effects/lpe-mirror_symmetry.cpp | 134 | ||||
| -rw-r--r-- | src/live_effects/lpe-mirror_symmetry.h | 9 |
2 files changed, 104 insertions, 39 deletions
diff --git a/src/live_effects/lpe-mirror_symmetry.cpp b/src/live_effects/lpe-mirror_symmetry.cpp index e4ae0bbdb..f34421df2 100644 --- a/src/live_effects/lpe-mirror_symmetry.cpp +++ b/src/live_effects/lpe-mirror_symmetry.cpp @@ -15,6 +15,8 @@ */ #include <gtkmm.h> +#include "live_effects/lpeobject.h" +#include "live_effects/lpeobject-reference.h" #include "live_effects/lpe-mirror_symmetry.h" #include "display/curve.h" #include "svg/path-string.h" @@ -53,11 +55,10 @@ LPEMirrorSymmetry::LPEMirrorSymmetry(LivePathEffectObject *lpeobject) : discard_orig_path(_("Discard original path?"), _("Check this to only keep the mirrored part of the path"), "discard_orig_path", &wr, this, false), fuse_paths(_("Fuse paths"), _("Fuse original and the reflection into a single path"), "fuse_paths", &wr, this, false), oposite_fuse(_("Opposite fuse"), _("Picks the other side of the mirror as the original"), "oposite_fuse", &wr, this, false), - split_elements(_("Split elements"), _("Split elements, this allow gradients and other paints"), "split_elements", &wr, this, false), + split_elements(_("Split elements"), _("Split elements, this allow gradients and other paints. Group result to apply nested"), "split_elements", &wr, this, false), start_point(_("Start mirror line"), _("Start mirror line"), "start_point", &wr, this, _("Adjust the start of mirroring")), end_point(_("End mirror line"), _("End mirror line"), "end_point", &wr, this, _("Adjust end of mirroring")), - center_point(_("Center mirror line"), _("Center mirror line"), "center_point", &wr, this, _("Adjust center of mirroring")), - original("hidden", "hidden", "original", &wr, this,"") + center_point(_("Center mirror line"), _("Center mirror line"), "center_point", &wr, this, _("Adjust center of mirroring")) { show_orig_path = true; registerParameter(&mode); @@ -69,8 +70,6 @@ LPEMirrorSymmetry::LPEMirrorSymmetry(LivePathEffectObject *lpeobject) : registerParameter(&start_point); registerParameter(&end_point); registerParameter(¢er_point); - registerParameter(&original); - original.param_hide_canvas_text(); split_gap.param_set_range(-999999.0, 999999.0); split_gap.param_set_increments(0.1, 0.1); split_gap.param_set_digits(2); @@ -157,7 +156,7 @@ LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) if (!are_near(previous_center, center_point,0.01)) { center_point.param_setValue(previous_center); } - if (split_elements) { + if (split_elements && allow_split()) { container = dynamic_cast<SPObject *>(splpeitem->parent); SPDocument * doc = SP_ACTIVE_DOCUMENT; Inkscape::XML::Node *root = splpeitem->document->getReprRoot(); @@ -165,11 +164,10 @@ LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) if (root_origin != root) { return; } - const char * mirror_a = g_strdup(Glib::ustring(original.param_getSVGValue()).c_str()); - const char * mirror_b = g_strdup(Glib::ustring("mirror-").append(this->getRepr()->attribute("id")).c_str()); - if (std::strcmp(splpeitem->getId(), mirror_b) == 0) { - syncMirror(splpeitem, mirror_a); - } else { + const char * mirror = g_strdup(Glib::ustring("mirror-b-").append(this->getRepr()->attribute("id")).c_str()); +// if (std::strcmp(splpeitem->getId(), mirror_b) == 0) { +// syncMirror(splpeitem, mirror_a); +// } else { Geom::Point point_a(line_separation.initialPoint()); Geom::Point point_b(line_separation.finalPoint()); Geom::Point gap(split_gap,0); @@ -191,14 +189,15 @@ LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) m = m * m2.inverse(); m = m * m1; m = m * splpeitem->transform; - //if (std::strcmp(splpeitem->getId(), mirror_b) != 0) { - createMirror(splpeitem, m, mirror_b); - } - elements.clear(); - elements.push_back(mirror_b); + createMirror(splpeitem, m); + //} } else { - elements.clear(); + if (!allow_split()) { + std::cout << "Only one operation of split allowed. Group results to nested effects.\n"; + split_elements.param_setValue(false); + } processObjects(LPE_ERASE); + elements.clear(); } } @@ -265,9 +264,19 @@ LPEMirrorSymmetry::cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, c } void -LPEMirrorSymmetry::createMirror(SPLPEItem *origin, Geom::Affine transform, const char * id) +LPEMirrorSymmetry::createMirror(SPLPEItem *origin, Geom::Affine transform) { if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { + const char * id; + Glib::ustring idbase = Glib::ustring(sp_lpe_item->getId()); + size_t pos = idbase.find("-mirror"); + if (pos <= idbase.size()) { + id = g_strdup(idbase.substr(pos).c_str()); + } else { + id = g_strdup(idbase.append("-mirror").c_str()); + elements.clear(); + elements.push_back(id); + } Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); Inkscape::URI SVGElem_uri(Glib::ustring("#").append(id).c_str()); Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); @@ -284,7 +293,7 @@ LPEMirrorSymmetry::createMirror(SPLPEItem *origin, Geom::Affine transform, const elemref = container->appendChildRepr(phantom); Inkscape::GC::release(phantom); } - cloneAttrbutes(SP_OBJECT(origin), elemref, true, "inkscape:original-d", NULL); //NULL required + cloneAttrbutes(SP_OBJECT(origin), elemref, true, "inkscape:original-d", "inkscape:path-effect", NULL); //NULL required elemref->getRepr()->setAttribute("transform" , sp_svg_transform_write(transform)); if (elemref->parent != container) { Inkscape::XML::Node *copy = phantom->duplicate(xml_doc); @@ -296,22 +305,77 @@ LPEMirrorSymmetry::createMirror(SPLPEItem *origin, Geom::Affine transform, const } } -void -LPEMirrorSymmetry::syncMirror(SPLPEItem *origin, const char * id) -{ - if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { - Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); - Inkscape::URI SVGElem_uri(Glib::ustring("#").append(id).c_str()); - Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); - SVGElemRef->attach(SVGElem_uri); - SPObject *elemref= NULL; - Inkscape::XML::Node *phantom = NULL; - if (elemref = SVGElemRef->getObject()) { - cloneAttrbutes(SP_OBJECT(origin), elemref, true, "inkscape:original-d", "inkscape:path-effect", NULL); //NULL required +//void +//LPEMirrorSymmetry::syncMirror(SPLPEItem *origin, const char * id) +//{ +// if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { +// Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); +// Inkscape::URI SVGElem_uri(Glib::ustring("#").append(id).c_str()); +// Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); +// SVGElemRef->attach(SVGElem_uri); +// SPObject *elemref= NULL; +// Inkscape::XML::Node *phantom = NULL; +// if (elemref = SVGElemRef->getObject()) { +// cloneAttrbutes(SP_OBJECT(origin), elemref, true, "inkscape:original-d", "inkscape:path-effect", NULL); //NULL required +// } +// } +//} + +bool +LPEMirrorSymmetry::allow_split(){ + if (sp_lpe_item->path_effect_list->empty()) { + return false; + } + size_t count = 0; + for (PathEffectList::const_iterator it = sp_lpe_item->path_effect_list->begin(); it != sp_lpe_item->path_effect_list->end(); ++it) + { + LivePathEffectObject *lpeobj = (*it)->lpeobject; + if (lpeobj) { + Inkscape::LivePathEffect::LPEMirrorSymmetry * ms = dynamic_cast<Inkscape::LivePathEffect::LPEMirrorSymmetry *>(lpeobj->get_lpe()); + if (ms && ms->split_elements) { + count++; + } } } + return count <= 1; } +//Gtk::Widget * +//LPEMirrorSymmetry::newWidget() +//{ +// // use manage here, because after deletion of Effect object, others might +// // still be pointing to this widget. +// Gtk::VBox *vbox = Gtk::manage(new Gtk::VBox(Effect::newWidget())); + +// vbox->set_border_width(5); +// std::vector<Parameter *>::iterator it = param_vector.begin(); +// while (it != param_vector.end()) { +// if ((*it)->widget_is_visible) { +// Parameter *param = *it; +// Gtk::Widget *widg = dynamic_cast<Gtk::Widget *>(param->param_newWidget()); +// if (widg) { +// if (param->param_key == "split_elements") { +// Gtk::CheckButton *widg_registered = Gtk::manage(dynamic_cast<Gtk::CheckButton *>(widg)); +// if (!allow_split()) { +// widg_registered->set_sensitive("false"); +// } +// widg = dynamic_cast<Gtk::Widget *>(widg_registered); +// } +// Glib::ustring *tip = param->param_getTooltip(); +// vbox->pack_start(*widg, true, true, 2); +// if (tip) { +// widg->set_tooltip_text(*tip); +// } else { +// widg->set_tooltip_text(""); +// widg->set_has_tooltip(false); +// } +// } +// } + +// ++it; +// } +// return dynamic_cast<Gtk::Widget *>(vbox); +//} //TODO: Migrate the tree next function to effect.cpp/h to avoid duplication void @@ -419,12 +483,12 @@ LPEMirrorSymmetry::doOnApply (SPLPEItem const* lpeitem) end_point.param_update_default(point_b); center_point.param_setValue(point_c); previous_center = center_point; - original.param_setValue(lpeitem->getId()); - original.write_to_SVG(); // SPLPEItem * splpeitem = const_cast<SPLPEItem *>(lpeitem); -// Glib::ustring mirror_a = Glib::ustring("mirror-a-").append(this->getRepr()->attribute("id")); // if (!lpeitem->hasPathEffectOfType(this->effectType(), false) ){ //first applied not ready yet -// splpeitem->getRepr()->setAttribute("id", mirror_a.c_str()); +// const char * mirror_a = g_strdup(Glib::ustring("mirror-a-").append(this->getRepr()->attribute("id")).c_str()); +// splpeitem->setAttribute("id", mirror_a); +// first_lpe.param_setValue(this->getRepr()->attribute("id")); +// first_lpe.write_to_SVG(); // } } diff --git a/src/live_effects/lpe-mirror_symmetry.h b/src/live_effects/lpe-mirror_symmetry.h index 3a78db169..12ceebaf8 100644 --- a/src/live_effects/lpe-mirror_symmetry.h +++ b/src/live_effects/lpe-mirror_symmetry.h @@ -17,8 +17,8 @@ */ #include "live_effects/effect.h" -#include "live_effects/parameter/text.h" #include "live_effects/parameter/parameter.h" +#include "live_effects/parameter/text.h" #include "live_effects/parameter/point.h" #include "live_effects/parameter/path.h" #include "live_effects/parameter/enum.h" @@ -46,11 +46,13 @@ public: virtual Geom::PathVector doEffect_path (Geom::PathVector const & path_in); virtual void doOnRemove (SPLPEItem const* /*lpeitem*/); virtual void doOnVisibilityToggled(SPLPEItem const* /*lpeitem*/); +// virtual Gtk::Widget * newWidget(); void processObjects(LpeAction lpe_action); - void createMirror(SPLPEItem *origin, Geom::Affine transform, const char * id); + void createMirror(SPLPEItem *origin, Geom::Affine transform); // void cloneAttrbutes(Inkscape::XML::Node * origin, Inkscape::XML::Node * dest, const char * first_attribute, ...); - void syncMirror(SPLPEItem *origin, const char * id); +// void syncMirror(SPLPEItem *origin, const char * id); void cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, const char * first_attribute, ...); + bool allow_split(); protected: virtual void addCanvasIndicators(SPLPEItem const *lpeitem, std::vector<Geom::PathVector> &hp_vec); @@ -65,7 +67,6 @@ private: PointParam start_point; PointParam end_point; PointParam center_point; - TextParam original; Geom::Line line_separation; Geom::Point previous_center; std::vector<const char *> elements; |
