diff options
| author | Jabiertxof <jtx@jtx> | 2016-12-08 22:22:16 +0000 |
|---|---|---|
| committer | Jabiertxof <jtx@jtx> | 2016-12-08 22:22:16 +0000 |
| commit | 76dc7d78c1f595659cb32d34bf046e13fe08721e (patch) | |
| tree | 25291193961123a93ad7634c6bd049891554f461 /src | |
| parent | Noumerous bugfixes (diff) | |
| download | inkscape-76dc7d78c1f595659cb32d34bf046e13fe08721e.tar.gz inkscape-76dc7d78c1f595659cb32d34bf046e13fe08721e.zip | |
Working on nested LPE
(bzr r15295.1.19)
Diffstat (limited to 'src')
| -rw-r--r-- | src/live_effects/lpe-mirror_symmetry.cpp | 146 | ||||
| -rw-r--r-- | src/live_effects/lpe-mirror_symmetry.h | 13 | ||||
| -rw-r--r-- | src/sp-lpe-item.cpp | 6 | ||||
| -rw-r--r-- | src/sp-lpe-item.h | 2 |
4 files changed, 40 insertions, 127 deletions
diff --git a/src/live_effects/lpe-mirror_symmetry.cpp b/src/live_effects/lpe-mirror_symmetry.cpp index 11620b23f..8225c152f 100644 --- a/src/live_effects/lpe-mirror_symmetry.cpp +++ b/src/live_effects/lpe-mirror_symmetry.cpp @@ -43,17 +43,6 @@ static const Util::EnumData<ModeType> ModeTypeData[MT_END] = { static const Util::EnumDataConverter<ModeType> MTConverter(ModeTypeData, MT_END); -namespace MS { - -class KnotHolderEntityCenterMirrorSymmetry : public LPEKnotHolderEntity { -public: - KnotHolderEntityCenterMirrorSymmetry(LPEMirrorSymmetry *effect) : LPEKnotHolderEntity(effect){}; - virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state); - virtual Geom::Point knot_get() const; -}; - -} // namespace MS - LPEMirrorSymmetry::LPEMirrorSymmetry(LivePathEffectObject *lpeobject) : Effect(lpeobject), mode(_("Mode"), _("Symmetry move mode"), "mode", MTConverter, &wr, this, MT_FREE), @@ -62,9 +51,9 @@ LPEMirrorSymmetry::LPEMirrorSymmetry(LivePathEffectObject *lpeobject) : 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), - 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"), - id_origin("id_origin", "id_origin", "id_origin", &wr, this,"") + 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")) { show_orig_path = true; registerParameter(&mode); @@ -75,13 +64,12 @@ LPEMirrorSymmetry::LPEMirrorSymmetry(LivePathEffectObject *lpeobject) : registerParameter( &split_elements); registerParameter( &start_point); registerParameter( &end_point); - registerParameter( &id_origin); - id_origin.param_hide_canvas_text(); + registerParameter( ¢er_point); split_gap.param_set_range(-999999.0, 999999.0); split_gap.param_set_increments(0.1, 0.1); split_gap.param_set_digits(2); apply_to_clippath_and_mask = true; - actual = true; + previous_center = Geom::Point(0,0); } LPEMirrorSymmetry::~LPEMirrorSymmetry() @@ -94,11 +82,10 @@ LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) SPLPEItem * splpeitem = const_cast<SPLPEItem *>(lpeitem); if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { Inkscape::Selection *sel = desktop->getSelection(); - if ( sel && !sel->isEmpty() && actual) { + if ( sel && !sel->isEmpty()) { SPItem *item = sel->singleItem(); if (item) { if(std::strcmp(splpeitem->getId(),item->getId()) != 0) { - actual = false; return; } } @@ -117,11 +104,14 @@ LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) point_a = Geom::Point(center_point[X],boundingbox_Y.min()); point_b = Geom::Point(center_point[X],boundingbox_Y.max()); } + if (Geom::are_near((Geom::Point)start_point, (Geom::Point)end_point, 0.01)) { + start_point.param_setValue(point_a); + end_point.param_setValue(point_b); + } line_separation.setPoints(point_a, point_b); if ( mode == MT_X || mode == MT_Y ) { start_point.param_setValue(point_a); end_point.param_setValue(point_b); - center_point = Geom::middle_point(point_a, point_b); } else if ( mode == MT_FREE) { if(!are_near(previous_center,center_point, 0.01)) { Geom::Point trans = center_point - previous_center; @@ -129,7 +119,6 @@ LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) end_point.param_setValue(end_point * trans); line_separation.setPoints(start_point, end_point); } else { - center_point = Geom::middle_point((Geom::Point)start_point, (Geom::Point)end_point); line_separation.setPoints(start_point, end_point); } } else if ( mode == MT_V){ @@ -142,7 +131,6 @@ LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) Geom::Point ep = Geom::Point(view_box_rect.width()/2.0, view_box_rect.height()); ep *= i2anc_affine(SP_OBJECT(lpeitem), SP_OBJECT(SP_ACTIVE_DESKTOP->currentLayer()->parent)) .inverse(); end_point.param_setValue(ep); - center_point = Geom::middle_point((Geom::Point)start_point, (Geom::Point)end_point); line_separation.setPoints(start_point, end_point); } } else { //horizontal page @@ -155,11 +143,14 @@ LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) Geom::Point ep = Geom::Point(view_box_rect.width(), view_box_rect.height()/2.0); ep *= i2anc_affine(SP_OBJECT(lpeitem), SP_OBJECT(SP_ACTIVE_DESKTOP->currentLayer()->parent)) .inverse(); end_point.param_setValue(ep); - center_point = Geom::middle_point((Geom::Point)start_point, (Geom::Point)end_point); line_separation.setPoints(start_point, end_point); } } - previous_center = center_point; + + previous_center = Geom::middle_point((Geom::Point)start_point, (Geom::Point)end_point); + if (!are_near(previous_center, center_point,0.01)) { + center_point.param_setValue(previous_center); + } if (split_elements) { ms_container = dynamic_cast<SPObject *>(splpeitem->parent); SPDocument * doc = SP_ACTIVE_DOCUMENT; @@ -168,6 +159,7 @@ LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) if (root_origin != root) { return; } + Geom::Point point_a(line_separation.initialPoint()); Geom::Point point_b(line_separation.finalPoint()); Geom::Point gap(split_gap,0); @@ -184,21 +176,22 @@ LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) Geom::Point offset = (point_a + point_b)/2 + dir.ccw() * split_gap; line_separation *= Geom::Translate(offset); Geom::Scale sca(1.0, -1.0); - const char * id_original = id_origin.param_getSVGValue(); - const char * id = g_strdup(Glib::ustring("mirror-").append(id_original).append("-").append(this->getRepr()->attribute("id")).c_str()); + const char * mirror_a = g_strdup(Glib::ustring("mirror-a-").append(this->getRepr()->attribute("id")).c_str()); + const char * mirror_b = g_strdup(Glib::ustring("mirror-b-").append(this->getRepr()->attribute("id")).c_str()); m = m1.inverse() * m2; m = m * sca; m = m * m2.inverse(); m = m * m1; m = m * lpeitem->transform; - if (std::strcmp(splpeitem->getId(), id) == 0) { - createMirror(splpeitem, m, id_original); - } else { - createMirror(splpeitem, m, id); + if (std::strcmp(splpeitem->getId(), mirror_a) != 0) { + createMirror(splpeitem, m, mirror_a); + } + if (std::strcmp(splpeitem->getId(), mirror_b) != 0) { + createMirror(splpeitem, m, mirror_b); } elements.clear(); - elements.push_back(id); - elements.push_back(id_original); + elements.push_back(mirror_a); + elements.push_back(mirror_b); } else { elements.clear(); processObjects(LPE_ERASE); @@ -288,7 +281,7 @@ LPEMirrorSymmetry::createMirror(SPLPEItem *origin, Geom::Affine transform, const elemref = ms_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 != ms_container) { Inkscape::XML::Node *copy = phantom->duplicate(xml_doc); @@ -349,7 +342,7 @@ LPEMirrorSymmetry::processObjects(LpeAction lpe_action) break; case LPE_ERASE: - if (std::strcmp(elemref->getId(),id_origin.param_getSVGValue()) != 0) { + if (std::strcmp(elemref->getId(),sp_lpe_item->getId()) != 0) { elemref->deleteObject(); } break; @@ -357,7 +350,7 @@ LPEMirrorSymmetry::processObjects(LpeAction lpe_action) case LPE_VISIBILITY: css = sp_repr_css_attr_new(); sp_repr_css_attr_add_from_string(css, elemref->getRepr()->attribute("style")); - if (!this->isVisible() && std::strcmp(elemref->getId(),id_origin.param_getSVGValue()) != 0) { + if (!this->isVisible() && std::strcmp(elemref->getId(),sp_lpe_item->getId()) != 0) { css->setAttribute("display", "none"); } else { css->setAttribute("display", NULL); @@ -382,8 +375,6 @@ void LPEMirrorSymmetry::transform_multiply(Geom::Affine const& postmul, bool set) { if( !split_elements) { - center_point *= postmul; - previous_center = center_point; // cycle through all parameters. Most parameters will not need transformation, but path and point params do. for (std::vector<Parameter *>::iterator it = param_vector.begin(); it != param_vector.end(); ++it) { Parameter * param = *it; @@ -406,10 +397,13 @@ LPEMirrorSymmetry::doOnApply (SPLPEItem const* lpeitem) start_point.param_update_default(point_a); end_point.param_setValue(point_b); end_point.param_update_default(point_b); - center_point = point_c; + center_point.param_setValue(point_c); previous_center = center_point; - id_origin.param_setValue(Glib::ustring(lpeitem->getId())); - id_origin.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()); + } } @@ -560,41 +554,6 @@ LPEMirrorSymmetry::doEffect_path (Geom::PathVector const & path_in) return path_out; } - -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); - vbox->set_homogeneous(false); - vbox->set_spacing(2); - - 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()); - Glib::ustring *tip = param->param_getTooltip(); - if (widg) { - if (param->param_key != "id_origin") { - 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); -} - void LPEMirrorSymmetry::addCanvasIndicators(SPLPEItem const */*lpeitem*/, std::vector<Geom::PathVector> &hp_vec) { @@ -610,43 +569,6 @@ LPEMirrorSymmetry::addCanvasIndicators(SPLPEItem const */*lpeitem*/, std::vector hp_vec.push_back(helper); } -void -LPEMirrorSymmetry::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item) -{ - SPKnotShapeType knot_shape = SP_KNOT_SHAPE_CIRCLE; - SPKnotModeType knot_mode = SP_KNOT_MODE_XOR; - guint32 knot_color = 0x0000ff00; - { - KnotHolderEntity *c = new MS::KnotHolderEntityCenterMirrorSymmetry(this); - c->create( desktop, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, - _("Adjust the center"), knot_shape, knot_mode, knot_color ); - knotholder->add(c); - } -}; - -namespace MS { - -using namespace Geom; - -void -KnotHolderEntityCenterMirrorSymmetry::knot_set(Geom::Point const &p, Geom::Point const &origin, guint state) -{ - LPEMirrorSymmetry* lpe = dynamic_cast<LPEMirrorSymmetry *>(_effect); - Geom::Point const s = snap_knot_position(p, state); - lpe->center_point = s; - // FIXME: this should not directly ask for updating the item. It should write to SVG, which triggers updating. - sp_lpe_item_update_patheffect (SP_LPE_ITEM(item), false, true); -} - -Geom::Point -KnotHolderEntityCenterMirrorSymmetry::knot_get() const -{ - LPEMirrorSymmetry const *lpe = dynamic_cast<LPEMirrorSymmetry const*>(_effect); - return lpe->center_point; -} - -} // namespace CR - } //namespace LivePathEffect } /* namespace Inkscape */ diff --git a/src/live_effects/lpe-mirror_symmetry.h b/src/live_effects/lpe-mirror_symmetry.h index 7b090ed82..fba16c750 100644 --- a/src/live_effects/lpe-mirror_symmetry.h +++ b/src/live_effects/lpe-mirror_symmetry.h @@ -27,11 +27,6 @@ namespace Inkscape { namespace LivePathEffect { -namespace MS { -// we need a separate namespace to avoid clashes with LPEPerpBisector -class KnotHolderEntityCenterMirrorSymmetry; -} - enum ModeType { MT_V, MT_H, @@ -51,14 +46,10 @@ 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); - /* the knotholder entity classes must be declared friends */ - friend class MS::KnotHolderEntityCenterMirrorSymmetry; void createMirror(SPLPEItem *origin, Geom::Affine transform, const char * id); // void cloneAttrbutes(Inkscape::XML::Node * origin, Inkscape::XML::Node * dest, const char * first_attribute, ...); void cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, const char * first_attribute, ...); - void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item); protected: virtual void addCanvasIndicators(SPLPEItem const *lpeitem, std::vector<Geom::PathVector> &hp_vec); @@ -72,11 +63,9 @@ private: BoolParam split_elements; PointParam start_point; PointParam end_point; - TextParam id_origin; + PointParam center_point; Geom::Line line_separation; Geom::Point previous_center; - Geom::Point center_point; - bool actual; std::vector<const char *> elements; SPObject * ms_container; LPEMirrorSymmetry(const LPEMirrorSymmetry&); diff --git a/src/sp-lpe-item.cpp b/src/sp-lpe-item.cpp index 9cf9dadc1..98428512f 100644 --- a/src/sp-lpe-item.cpp +++ b/src/sp-lpe-item.cpp @@ -607,7 +607,7 @@ bool SPLPEItem::hasPathEffect() const return true; } -bool SPLPEItem::hasPathEffectOfType(int const type) const +bool SPLPEItem::hasPathEffectOfType(int const type, bool is_ready) const { if (path_effect_list->empty()) { return false; @@ -619,7 +619,9 @@ bool SPLPEItem::hasPathEffectOfType(int const type) const if (lpeobj) { Inkscape::LivePathEffect::Effect const* lpe = lpeobj->get_lpe(); if (lpe && (lpe->effectType() == type)) { - return true; + if (is_ready || lpe->isReady()) { + return true; + } } } } diff --git a/src/sp-lpe-item.h b/src/sp-lpe-item.h index 9e5cb3329..db4a0c7a3 100644 --- a/src/sp-lpe-item.h +++ b/src/sp-lpe-item.h @@ -73,7 +73,7 @@ public: bool pathEffectsEnabled() const; bool hasPathEffect() const; - bool hasPathEffectOfType(int const type) const; + bool hasPathEffectOfType(int const type, bool is_ready = true) const; bool hasPathEffectRecursive() const; Inkscape::LivePathEffect::Effect* getPathEffectOfType(int type); Inkscape::LivePathEffect::Effect const* getPathEffectOfType(int type) const; |
