From 7f991b154fd88d2ad53558828be8c56018dbc0d7 Mon Sep 17 00:00:00 2001 From: johanengelen Date: Fri, 17 Aug 2007 20:30:10 +0000 Subject: [PATCH] Fix LPE: * add default values for parameters * remove text for LPE_INVALID * update example for skel strokes * clean a bit of the code --- share/examples/live-path-effects-skeletal.svg | 23 ++-------- src/live_effects/effect.cpp | 44 ++++++++++++------- src/live_effects/effect.h | 11 +++-- src/live_effects/lpe-gears.cpp | 4 +- src/live_effects/lpe-skeletalstrokes.cpp | 15 +++---- src/live_effects/lpe-test-doEffect-stack.cpp | 4 +- src/live_effects/lpeobject-reference.cpp | 4 +- src/live_effects/lpeobject-reference.h | 4 +- src/live_effects/lpeobject.cpp | 1 - src/live_effects/parameter/enum.h | 32 +++++++------- src/live_effects/parameter/parameter.cpp | 8 ++-- src/live_effects/parameter/parameter.h | 18 +++++--- src/live_effects/parameter/path.cpp | 7 +-- src/live_effects/parameter/path.h | 11 +++-- src/live_effects/parameter/point.cpp | 17 +++---- src/live_effects/parameter/point.h | 11 +++-- 16 files changed, 114 insertions(+), 100 deletions(-) diff --git a/share/examples/live-path-effects-skeletal.svg b/share/examples/live-path-effects-skeletal.svg index 7f9917ee0..936b487b5 100644 --- a/share/examples/live-path-effects-skeletal.svg +++ b/share/examples/live-path-effects-skeletal.svg @@ -25,20 +25,6 @@ origin="0.1,0.2" pattern="M 119.92529,-0.41956101 C 119.92529,1.659909 120.58678,2.431279 121.32538,3.765079 C 120.76714,6.123869 120.41028,8.500889 122.37545,11.088229 C 121.671,13.006199 122.5692,14.924159 123.95054,16.842119 C 123.71907,18.682279 124.92357,20.284009 126.05068,21.898579 C 126.25318,23.990909 127.36543,26.083239 129.20088,28.175559 C 112.57483,22.944749 111.46952,10.168439 108.8996,7.775379 C 107.5348,6.504509 106.05778,6.654809 105.00417,5.064329 C 103.95056,3.473849 103.32038,0.14257899 102.24918,-0.41974101 C 103.32038,-0.98206101 103.95056,-4.313331 105.00417,-5.903821 C 106.05778,-7.494301 107.5348,-7.343991 108.8996,-8.614861 C 111.46952,-11.007921 112.57483,-23.784231 129.20088,-29.015041 C 127.36543,-26.922721 126.25318,-24.830391 126.05068,-22.738061 C 124.92357,-21.123491 123.71907,-19.521771 123.95054,-17.681611 C 122.5692,-15.763641 121.671,-13.845681 122.37545,-11.927711 C 120.41028,-9.340371 120.76714,-6.963351 121.32538,-4.604571 C 120.58678,-3.270761 119.92529,-2.499391 119.92529,-0.41992101 M 102.24917,-9.399491 C 101.73918,-8.349411 101.40752,-7.043061 101.33869,-5.702881 M 97.931762,-12.373781 C 97.196772,-10.747321 96.683652,-9.149741 96.517362,-7.611401 M 40.796126,-31.951641 C 36.393294,-26.573831 34.489541,-20.703561 33.158143,-15.440541 M 92.314832,-9.032131 C 92.607472,-11.125331 93.016652,-13.311561 94.188102,-15.314231 M 69.466596,-14.799961 C 70.526116,-19.749901 72.232996,-25.173971 76.035906,-29.701501 M 76.247336,-13.550161 C 77.232456,-17.658201 78.546166,-22.280971 81.496132,-26.588961 M 81.688812,-12.160461 C 82.459442,-15.577031 83.798922,-19.288461 86.595282,-22.724941 M 87.619382,-10.586331 C 88.269962,-13.778381 89.079762,-17.038011 90.529502,-19.434311 M 39.372996,-16.390721 C 40.663096,-22.091891 42.448976,-28.160771 46.526886,-32.647581 M 44.719896,-16.786451 C 46.020076,-21.938221 48.120906,-27.667231 52.729216,-33.084921 M 51.186366,-16.832791 C 52.460916,-21.977761 54.401586,-27.698631 58.580646,-33.111011 M 57.755366,-16.454151 C 59.035266,-21.645811 60.894386,-27.451691 64.905486,-32.894161 M 70.743036,-31.820641 C 68.781736,-29.846411 65.654026,-23.126311 64.075116,-15.756401 M 32.943271,13.696999 C 31.02686,5.738139 30.600382,-0.45243101 26.863458,-0.37462101 C 30.736989,-0.29396101 30.793459,-6.970991 33.158143,-15.440541 C 32.058705,-10.280411 31.563422,-4.759601 33.107444,-0.37462101 C 31.648043,3.659839 31.768408,8.716679 32.943271,13.696999 z M 101.2948,4.002579 C 101.17471,1.399589 101.32632,-0.45999101 98.464912,-0.37462101 C 101.67522,-0.27884101 100.95543,-2.624431 101.33869,-5.702881 C 101.31622,-3.566861 101.64612,-1.440751 102.07417,-0.37462101 L 102.07417,-0.37461101 C 101.70843,0.53633899 101.30509,2.215759 101.2948,4.002579 z M 96.421272,5.945939 C 95.961022,1.675379 97.120182,-0.47020101 92.570952,-0.37462101 C 97.432252,-0.27249101 95.639582,-2.793851 96.517362,-7.611401 C 96.251492,-4.242461 97.074992,-1.421851 98.464912,-0.37462101 C 97.205982,0.57391899 96.293052,3.033689 96.421272,5.945939 z M 92.199792,7.369879 C 91.682072,3.112599 91.561712,-0.45910101 87.418402,-0.37462101 C 91.855932,-0.28415101 91.596802,-4.354961 92.314832,-9.032131 C 91.936652,-5.782151 91.961722,-2.262891 92.570952,-0.37462101 C 92.017822,1.339789 91.874662,4.370259 92.199792,7.369879 z M 69.316276,13.139069 C 67.797866,5.660429 67.642976,-0.45234101 63.912806,-0.37462101 C 67.774536,-0.29415101 67.758886,-6.940511 69.466596,-14.799961 C 68.459376,-9.690321 68.383356,-4.346991 70.151986,-0.37462101 C 68.463476,3.297119 68.413876,8.256599 69.316276,13.139069 z M 76.078836,11.926069 C 74.460446,4.871139 74.036686,-0.45624101 70.151986,-0.37462101 C 74.171726,-0.29017101 74.285226,-6.166821 76.247336,-13.550161 C 75.280136,-8.280741 74.927876,-2.963871 76.515186,-0.37462101 C 75.005646,1.958549 75.063016,6.925809 76.078836,11.926069 z M 81.510842,10.533629 C 80.232116,4.381079 80.563616,-0.45735101 76.515186,-0.37462101 C 80.723636,-0.28862101 80.257296,-5.632921 81.688812,-12.160461 C 80.480436,-7.730861 80.156206,-3.060491 81.828332,-0.37462101 C 80.253876,2.021669 80.503246,6.293799 81.510842,10.533629 z M 87.231632,9.011219 C 86.277232,3.962159 85.596432,-0.45378101 81.828332,-0.37462101 C 85.721262,-0.29283101 86.645572,-5.247951 87.619382,-10.586331 C 86.643642,-6.535971 86.369042,-2.355891 87.418402,-0.37462101 C 86.435402,1.337139 86.488032,5.129359 87.231632,9.011219 z M 39.188486,14.663929 C 37.426416,6.563309 36.714489,-0.45040101 33.107444,-0.37462101 C 36.841626,-0.29617101 37.280464,-7.861881 39.372996,-16.390721 C 38.458246,-11.472261 38.047626,-5.894711 39.116846,-0.37462101 C 38.108106,4.729069 38.236876,9.909499 39.188486,14.663929 z M 44.509636,15.084679 C 42.430096,6.289929 42.889186,-0.45620101 39.116846,-0.37462101 C 43.005546,-0.29052101 42.225876,-7.554121 44.719896,-16.786451 C 43.333526,-11.095791 42.850856,-4.991741 45.126236,-0.37462101 C 42.961866,3.900459 43.131256,9.595039 44.509636,15.084679 z M 50.990786,15.148389 C 48.912506,6.307419 49.021366,-0.45645101 45.126236,-0.37462101 C 49.135236,-0.29039101 48.729696,-7.576121 51.186366,-16.832791 C 49.925426,-11.117121 49.450086,-4.984491 51.399926,-0.37462101 C 49.545316,3.893529 49.721436,9.637169 50.990786,15.148389 z M 57.565346,14.782989 C 55.531406,6.152689 55.300196,-0.45545101 51.399926,-0.37462101 C 55.418466,-0.29134101 55.350966,-7.413051 57.755366,-16.454151 C 56.576046,-10.870761 56.066836,-4.924771 57.673626,-0.37462101 C 56.143836,3.842269 56.352086,9.409209 57.565346,14.782989 z M 63.897286,14.082869 C 61.995916,5.914449 61.453026,-0.45402101 57.673626,-0.37462101 C 61.576106,-0.29263101 61.875306,-7.194241 64.075116,-15.756401 C 63.069866,-10.454371 62.668056,-4.819531 63.912806,-0.37462101 C 62.730386,3.735449 62.890676,9.007129 63.897286,14.082869 z M 101.2948,4.002579 C 101.2854,5.635799 101.62236,7.359649 102.24917,8.650249 M 96.421272,5.945939 C 96.500192,7.738359 97.047242,9.667199 97.931762,11.624549 M 94.188102,14.564989 C 92.844012,12.267189 92.486012,9.723619 92.199792,7.369879 M 90.529502,18.685079 C 88.532242,15.921769 87.858722,12.328759 87.231632,9.011219 M 86.595282,21.975709 C 83.596552,18.186189 82.259812,14.137229 81.510842,10.533629 M 76.078836,11.926069 C 77.283916,17.857939 79.761566,23.856219 81.496132,25.839729 M 76.035906,28.952269 C 72.027436,24.064879 70.360566,18.282469 69.316276,13.139069 M 63.897286,14.082869 C 65.423906,21.780689 68.711106,29.026089 70.743036,31.071409 M 64.905486,32.144929 C 60.689146,26.315529 58.832476,20.159629 57.565346,14.782989 M 58.580646,32.361779 C 54.188676,26.567379 52.244036,20.479709 50.990786,15.148389 M 52.729216,32.335679 C 47.874606,26.521609 45.773926,20.431609 44.509636,15.084679 M 46.526886,31.898339 C 42.242406,27.064939 40.476646,20.585919 39.188486,14.663929 M 32.943271,13.696999 C 34.257898,19.156649 36.145459,25.406929 40.796126,31.202409 M 120.27531,-19.250851 C 122.72547,-21.866261 126.05068,-22.738061 126.05068,-22.738061 M 116.60008,-13.845671 C 119.57527,-16.461081 123.95054,-17.681611 123.95054,-17.681611 M 113.7999,-7.045611 C 117.82516,-11.578991 122.37545,-11.927711 122.37545,-11.927711 M 111.69977,-2.512241 C 116.7751,-4.604571 121.32538,-4.604571 121.32538,-4.604571 M 120.27531,18.411369 C 122.72547,21.026779 126.05068,21.898579 126.05068,21.898579 M 116.60008,13.006189 C 119.57527,15.621599 123.95054,16.842119 123.95054,16.842119 M 113.7999,6.206129 C 117.82516,10.739509 122.37545,11.088229 122.37545,11.088229 M 111.69977,1.672759 C 116.7751,3.765079 121.32538,3.765079 121.32538,3.765079 M 19.293941,-10.620001 C 19.293941,-10.186891 18.98032,-9.835381 18.593898,-9.835381 C 18.207472,-9.835381 17.893856,-10.186891 17.893856,-10.620001 C 17.893856,-11.053121 18.207472,-11.404621 18.593898,-11.404621 C 18.98032,-11.404621 19.293941,-11.053121 19.293941,-10.620001 z M 25.856859,27.564939 C 30.582156,27.477759 25.856859,6.205779 25.856859,-0.59428101 C 25.856859,-7.394341 27.795183,-22.180491 33.032312,-28.927861 C 38.358126,-35.789491 -1.283572,-12.994371 1.617831,4.810899 C 4.855537,6.641689 9.755844,7.600669 13.693591,9.082729 C 10.01836,9.344269 5.730588,8.210929 2.667892,7.426299 C 4.418006,11.087879 10.543393,21.200789 25.856859,27.564939 z M 21.219074,-11.796931 C 21.219074,-10.473531 20.297813,-9.399471 19.162695,-9.399471 C 18.027572,-9.399471 17.106311,-10.473531 17.106311,-11.796931 C 17.106311,-13.120321 18.027572,-14.194381 19.162695,-14.194381 C 20.297813,-14.194381 21.219074,-13.120321 21.219074,-11.796931 z M 19.293941,-10.620001 C 19.293941,-10.186891 18.98032,-9.835381 18.593898,-9.835381 C 18.207472,-9.835381 17.893856,-10.186891 17.893856,-10.620001 C 17.893856,-11.053121 18.207472,-11.404621 18.593898,-11.404621 C 18.98032,-11.404621 19.293941,-11.053121 19.293941,-10.620001 z" copytype="single_stretched" /> - - - + inkscape:original-d="M 503.49518,109.44533 C 555.807,22.673092 673.35319,31.460958 712.72285,112.87823" + sodipodi:nodetypes="cc" /> LPETypeData[ENDTYPE_LPE] = { - {INVALID_LPE, _("Invalid effect"), "invalid"}, +const Util::EnumData LPETypeData[INVALID_LPE] = { {SKELETAL_STROKES, _("Skeletal Strokes"), "skeletal"}, {SLANT, _("Slant"), "slant"}, {DOEFFECTSTACK_TEST, _("doEffect stack test"), "doeffectstacktest"}, {GEARS, _("Gears"), "gears"} }; -const Util::EnumDataConverter LPETypeConverter(LPETypeData, ENDTYPE_LPE); +const Util::EnumDataConverter LPETypeConverter(LPETypeData, INVALID_LPE); Effect* Effect::New(EffectType lpenr, LivePathEffectObject *lpeobj) { + Effect* neweffect = NULL; switch (lpenr) { - case INVALID_LPE: - g_warning("LivePathEffect::Effect::New called with invalid patheffect type"); - return NULL; case SKELETAL_STROKES: - return (Effect*) new LPESkeletalStrokes(lpeobj); + neweffect = (Effect*) new LPESkeletalStrokes(lpeobj); + break; case SLANT: - return (Effect*) new LPESlant(lpeobj); + neweffect = (Effect*) new LPESlant(lpeobj); + break; case DOEFFECTSTACK_TEST: - return (Effect*) new LPEdoEffectStackTest(lpeobj); + neweffect = (Effect*) new LPEdoEffectStackTest(lpeobj); + break; case GEARS: - return (Effect*) new LPEGears(lpeobj); - case ENDTYPE_LPE: - return NULL; + neweffect = (Effect*) new LPEGears(lpeobj); + break; + default: + g_warning("LivePathEffect::Effect::New called with invalid patheffect type (%d)", lpenr); + neweffect = NULL; + break; } - return NULL; + if (neweffect) { + neweffect->readallParameters(SP_OBJECT_REPR(lpeobj)); + } + + return neweffect; } Effect::Effect(LivePathEffectObject *lpeobject) @@ -83,7 +90,10 @@ Effect::~Effect() Glib::ustring Effect::getName() { - return Glib::ustring( LPETypeConverter.get_label(lpeobj->effecttype) ); + if (lpeobj->effecttype_set && lpeobj->effecttype < INVALID_LPE) + return Glib::ustring( LPETypeConverter.get_label(lpeobj->effecttype) ); + else + return Glib::ustring( _("No effect") ); } /* @@ -211,14 +221,14 @@ Effect::getRepr() SPDocument * Effect::getSPDoc() { - if (SP_OBJECT_DOCUMENT(lpeobj) == NULL) g_message("oh crap"); + if (SP_OBJECT_DOCUMENT(lpeobj) == NULL) g_message("Effect::getSPDoc() returns NULL"); return SP_OBJECT_DOCUMENT(lpeobj); } -}; /* namespace LivePathEffect */ +} /* namespace LivePathEffect */ -}; /* namespace Inkscape */ +} /* namespace Inkscape */ /* Local Variables: diff --git a/src/live_effects/effect.h b/src/live_effects/effect.h index 0ebd5d5a5..714bcdcab 100644 --- a/src/live_effects/effect.h +++ b/src/live_effects/effect.h @@ -39,15 +39,14 @@ namespace XML { namespace LivePathEffect { enum EffectType { - INVALID_LPE = 0, - SKELETAL_STROKES, + SKELETAL_STROKES = 0, SLANT, DOEFFECTSTACK_TEST, GEARS, - ENDTYPE_LPE // This must be last + INVALID_LPE // This must be last }; -extern const Util::EnumData LPETypeData[ENDTYPE_LPE]; +extern const Util::EnumData LPETypeData[INVALID_LPE]; extern const Util::EnumDataConverter LPETypeConverter; class Parameter; @@ -102,7 +101,7 @@ private: }; -}; //namespace LivePathEffect -}; //namespace Inkscape +} //namespace LivePathEffect +} //namespace Inkscape #endif diff --git a/src/live_effects/lpe-gears.cpp b/src/live_effects/lpe-gears.cpp index 8da819ef6..03e19f31c 100644 --- a/src/live_effects/lpe-gears.cpp +++ b/src/live_effects/lpe-gears.cpp @@ -251,8 +251,8 @@ LPEGears::doEffect (std::vector & path_in) } -}; // namespace LivePathEffect -}; /* namespace Inkscape */ +} // namespace LivePathEffect +} /* namespace Inkscape */ /* Local Variables: diff --git a/src/live_effects/lpe-skeletalstrokes.cpp b/src/live_effects/lpe-skeletalstrokes.cpp index 47c73a56b..e8cff9518 100644 --- a/src/live_effects/lpe-skeletalstrokes.cpp +++ b/src/live_effects/lpe-skeletalstrokes.cpp @@ -58,9 +58,9 @@ static const Util::EnumDataConverter SkelCopyTypeConverter(SkelCop LPESkeletalStrokes::LPESkeletalStrokes(LivePathEffectObject *lpeobject) : Effect(lpeobject), - pattern(_("Pattern"), _("Pattern to put along path"), "pattern", &wr, this), - origin(_("Origin"), _("Origin of ?"), "origin", &wr, this), - copytype(_("Copytype"), _("tooltip"), "copytype", SkelCopyTypeConverter, &wr, this) + pattern(_("Pattern"), _("Pattern to put along path"), "pattern", &wr, this, "M0,0 L1,1"), + origin(_("Origin"), _("Origin of ?"), "origin", &wr, this, Geom::Point(0,0)), + copytype(_("Copytype"), _("tooltip"), "copytype", SkelCopyTypeConverter, &wr, this, SSCT_SINGLE_STRETCHED) { registerParameter( dynamic_cast(&origin) ); registerParameter( dynamic_cast(&pattern) ); @@ -83,10 +83,7 @@ LPESkeletalStrokes::doEffect (Geom::Piecewise > & pwd2_in /* LOTS OF CODE COPIED FROM 2geom/src/toys/path-along-path.cpp * All credits should go to jfb and mgsloan of lib2geom development! */ - const Util::EnumData * data = copytype.get_selected_data(); - if (!data) - return pwd2_in; - SkelCopyType type = data->id; + SkelCopyType type = copytype.get_value(); Piecewise > uskeleton = arc_length_parametrization(Piecewise >(pwd2_in),2,.1); uskeleton = remove_short_cuts(uskeleton,.01); @@ -146,8 +143,8 @@ LPESkeletalStrokes::on_pattern_pasted() -}; // namespace LivePathEffect -}; /* namespace Inkscape */ +} // namespace LivePathEffect +} /* namespace Inkscape */ /* Local Variables: diff --git a/src/live_effects/lpe-test-doEffect-stack.cpp b/src/live_effects/lpe-test-doEffect-stack.cpp index 2e3d12725..346d79c9d 100644 --- a/src/live_effects/lpe-test-doEffect-stack.cpp +++ b/src/live_effects/lpe-test-doEffect-stack.cpp @@ -81,8 +81,8 @@ LPEdoEffectStackTest::doEffect (Geom::Piecewise > & pwd2_ } -}; // namespace LivePathEffect -}; /* namespace Inkscape */ +} // namespace LivePathEffect +} /* namespace Inkscape */ /* Local Variables: diff --git a/src/live_effects/lpeobject-reference.cpp b/src/live_effects/lpeobject-reference.cpp index a5392ef90..e4def4301 100644 --- a/src/live_effects/lpeobject-reference.cpp +++ b/src/live_effects/lpeobject-reference.cpp @@ -145,9 +145,9 @@ lpeobjectreference_source_modified(SPObject *iSource, guint flags, LPEObjectRefe lpeobjref->owner->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); } -}; //namespace LivePathEffect +} //namespace LivePathEffect -}; // namespace inkscape +} // namespace inkscape /* Local Variables: diff --git a/src/live_effects/lpeobject-reference.h b/src/live_effects/lpeobject-reference.h index 7aaa5f691..ff7556d50 100644 --- a/src/live_effects/lpeobject-reference.h +++ b/src/live_effects/lpeobject-reference.h @@ -53,9 +53,9 @@ protected: }; -}; //namespace LivePathEffect +} //namespace LivePathEffect -}; // namespace inkscape +} // namespace inkscape #endif /* !SEEN_LPEOBJECT_REFERENCE_H */ diff --git a/src/live_effects/lpeobject.cpp b/src/live_effects/lpeobject.cpp index 0ce2ce283..de2baa470 100644 --- a/src/live_effects/lpeobject.cpp +++ b/src/live_effects/lpeobject.cpp @@ -179,7 +179,6 @@ livepatheffect_set(SPObject *object, unsigned key, gchar const *value) lpeobj->effecttype = Inkscape::LivePathEffect::LPETypeConverter.get_id_from_key(value); if (lpeobj->effecttype != Inkscape::LivePathEffect::INVALID_LPE) { lpeobj->lpe = Inkscape::LivePathEffect::Effect::New(lpeobj->effecttype, lpeobj); - lpeobj->lpe->readallParameters(SP_OBJECT_REPR(object)); } lpeobj->effecttype_set = true; } else { diff --git a/src/live_effects/parameter/enum.h b/src/live_effects/parameter/enum.h index d70360a24..bfc9fd352 100644 --- a/src/live_effects/parameter/enum.h +++ b/src/live_effects/parameter/enum.h @@ -28,11 +28,14 @@ public: const Glib::ustring& tip, const Glib::ustring& key, const Util::EnumDataConverter& c, - Inkscape::UI::Widget::Registry* wr, Effect* effect) + Inkscape::UI::Widget::Registry* wr, + Effect* effect, + E defvalue) : Parameter(label, tip, key, wr, effect) { regenum = NULL; enumdataconv = &c; + value = defvalue; }; ~EnumParam() { if (regenum) @@ -44,37 +47,36 @@ public: regenum = new Inkscape::UI::Widget::RegisteredEnum(); regenum->init(param_label, param_tooltip, param_key, *enumdataconv, *param_wr, param_effect->getRepr(), param_effect->getSPDoc()); regenum->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change enum parameter")); + regenum->combobox()->set_active_by_id(value); } return dynamic_cast (regenum->labelled); }; bool param_readSVGValue(const gchar * strvalue) { + if (!strvalue) return false; + + value = enumdataconv->get_id_from_key(Glib::ustring(strvalue)); + if (regenum) - regenum->combobox()->set_active_by_key(Glib::ustring(strvalue)); + regenum->combobox()->set_active_by_id(value); + return true; }; gchar * param_writeSVGValue() const { - if (regenum) { - gchar * str = g_strdup(regenum->combobox()->get_active_data()->key.c_str()); - return str; - } else { - return NULL; - } + gchar * str = g_strdup( enumdataconv->get_key(value).c_str() ); + return str; }; - const Util::EnumData* get_selected_data() { - if (regenum) { - return regenum->combobox()->get_active_data(); - } else { - return NULL; - } - }; + E get_value() const { + return value; + } private: EnumParam(const EnumParam&); EnumParam& operator=(const EnumParam&); UI::Widget::RegisteredEnum * regenum; + E value; const Util::EnumDataConverter * enumdataconv; }; diff --git a/src/live_effects/parameter/parameter.cpp b/src/live_effects/parameter/parameter.cpp index 6806a1d49..beaafcc22 100644 --- a/src/live_effects/parameter/parameter.cpp +++ b/src/live_effects/parameter/parameter.cpp @@ -62,6 +62,8 @@ RealParam::param_readSVGValue(const gchar * strvalue) unsigned int success = sp_svg_number_read_d(strvalue, &newval); if (success == 1) { value = newval; + if (rsu) + rsu->setValue(value); return true; } return false; @@ -71,7 +73,7 @@ gchar * RealParam::param_writeSVGValue() const { Inkscape::SVGOStringStream os; - os << rsu->getS()->getValue(); + os << value; gchar * str = g_strdup(os.str().c_str()); return str; } @@ -89,9 +91,9 @@ RealParam::param_getWidget() } -}; /* namespace LivePathEffect */ +} /* namespace LivePathEffect */ -}; /* namespace Inkscape */ +} /* namespace Inkscape */ /* Local Variables: diff --git a/src/live_effects/parameter/parameter.h b/src/live_effects/parameter/parameter.h index 327d3d153..93cdc94ee 100644 --- a/src/live_effects/parameter/parameter.h +++ b/src/live_effects/parameter/parameter.h @@ -28,7 +28,11 @@ class Effect; class Parameter { public: - Parameter(const Glib::ustring& label, const Glib::ustring& tip, const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr, Effect* effect); + Parameter( const Glib::ustring& label, + const Glib::ustring& tip, + const Glib::ustring& key, + Inkscape::UI::Widget::Registry* wr, + Effect* effect); virtual ~Parameter() {}; virtual bool param_readSVGValue(const gchar * strvalue) = 0; // returns true if new value is valid / accepted. @@ -56,8 +60,12 @@ private: class RealParam : public Parameter { public: - RealParam( const Glib::ustring& label, const Glib::ustring& tip, const Glib::ustring& key, - Inkscape::UI::Widget::Registry* wr, Effect* effect, gdouble initial_value = 1.0); + RealParam( const Glib::ustring& label, + const Glib::ustring& tip, + const Glib::ustring& key, + Inkscape::UI::Widget::Registry* wr, + Effect* effect, + gdouble initial_value = 1.0); ~RealParam(); bool param_readSVGValue(const gchar * strvalue); @@ -77,8 +85,8 @@ private: }; -}; //namespace LivePathEffect +} //namespace LivePathEffect -}; //namespace Inkscape +} //namespace Inkscape #endif diff --git a/src/live_effects/parameter/path.cpp b/src/live_effects/parameter/path.cpp index 90974f686..d2615901f 100644 --- a/src/live_effects/parameter/path.cpp +++ b/src/live_effects/parameter/path.cpp @@ -33,11 +33,12 @@ namespace LivePathEffect { PathParam::PathParam( const Glib::ustring& label, const Glib::ustring& tip, const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr, - Effect* effect ) + Effect* effect, const gchar * defvalue) : Parameter(label, tip, key, wr, effect) { _widget = NULL; _tooltips = NULL; + param_readSVGValue(defvalue); } PathParam::~PathParam() @@ -150,9 +151,9 @@ PathParam::param_write_to_repr(const char * svgd) } -}; /* namespace LivePathEffect */ +} /* namespace LivePathEffect */ -}; /* namespace Inkscape */ +} /* namespace Inkscape */ /* Local Variables: diff --git a/src/live_effects/parameter/path.h b/src/live_effects/parameter/path.h index 39ea9e2d8..18ffe5321 100644 --- a/src/live_effects/parameter/path.h +++ b/src/live_effects/parameter/path.h @@ -25,7 +25,12 @@ namespace LivePathEffect { class PathParam : public Geom::Piecewise >, public Parameter { public: - PathParam(const Glib::ustring& label, const Glib::ustring& tip, const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr, Effect* effect);; + PathParam ( const Glib::ustring& label, + const Glib::ustring& tip, + const Glib::ustring& key, + Inkscape::UI::Widget::Registry* wr, + Effect* effect, + const gchar * defvalue = "M0,0 L1,1"); ~PathParam(); Gtk::Widget * param_getWidget(); @@ -49,8 +54,8 @@ private: }; -}; //namespace LivePathEffect +} //namespace LivePathEffect -}; //namespace Inkscape +} //namespace Inkscape #endif diff --git a/src/live_effects/parameter/point.cpp b/src/live_effects/parameter/point.cpp index 8079f54eb..39208ad62 100644 --- a/src/live_effects/parameter/point.cpp +++ b/src/live_effects/parameter/point.cpp @@ -29,8 +29,8 @@ namespace LivePathEffect { PointParam::PointParam( const Glib::ustring& label, const Glib::ustring& tip, const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr, - Effect* effect ) - : Geom::Point(0,0), Parameter(label, tip, key, wr, effect) + Effect* effect, Geom::Point defvalue ) + : Geom::Point(defvalue), Parameter(label, tip, key, wr, effect) { _widget = NULL; pointwdg = NULL; @@ -58,7 +58,7 @@ PointParam::param_readSVGValue(const gchar * strvalue) success += sp_svg_number_read_d(strarray[1], &newy); g_strfreev (strarray); if (success == 2) { - *dynamic_cast( this ) = Geom::Point(newx, newy); + param_setValue( Geom::Point(newx, newy) ); return true; } return false; @@ -68,7 +68,7 @@ gchar * PointParam::param_writeSVGValue() const { Inkscape::SVGOStringStream os; - os << pointwdg->getPoint()->getXValue() << "," << pointwdg->getPoint()->getYValue(); + os << (*this)[0] << "," << (*this)[1]; gchar * str = g_strdup(os.str().c_str()); return str; } @@ -79,7 +79,7 @@ PointParam::param_getWidget() if (!_widget) { pointwdg = new Inkscape::UI::Widget::RegisteredPoint(); pointwdg->init(param_label, param_tooltip, param_key, *param_wr, param_effect->getRepr(), param_effect->getSPDoc()); - pointwdg->setValue(0.1, 0.2); + pointwdg->setValue( (*this)[0], (*this)[1] ); pointwdg->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change point parameter")); Gtk::Widget* pIcon = Gtk::manage( sp_icon_get_icon( "draw_node", Inkscape::ICON_SIZE_BUTTON) ); @@ -108,7 +108,8 @@ void PointParam::param_setValue(Geom::Point newpoint) { *dynamic_cast( this ) = newpoint; - pointwdg->setValue(newpoint[0], newpoint[1]); + if (pointwdg) + pointwdg->setValue(newpoint[0], newpoint[1]); } @@ -150,9 +151,9 @@ PointParam::on_button_click() } } -}; /* namespace LivePathEffect */ +} /* namespace LivePathEffect */ -}; /* namespace Inkscape */ +} /* namespace Inkscape */ /* Local Variables: diff --git a/src/live_effects/parameter/point.h b/src/live_effects/parameter/point.h index 1240ea3d1..368ab63ed 100644 --- a/src/live_effects/parameter/point.h +++ b/src/live_effects/parameter/point.h @@ -27,7 +27,12 @@ namespace LivePathEffect { class PointParam : public Geom::Point, public Parameter { public: - PointParam(const Glib::ustring& label, const Glib::ustring& tip, const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr, Effect* effect);; + PointParam( const Glib::ustring& label, + const Glib::ustring& tip, + const Glib::ustring& key, + Inkscape::UI::Widget::Registry* wr, + Effect* effect, + Geom::Point defvalue = Geom::Point(0,0)); ~PointParam(); Gtk::Widget * param_getWidget(); @@ -50,8 +55,8 @@ private: }; -}; //namespace LivePathEffect +} //namespace LivePathEffect -}; //namespace Inkscape +} //namespace Inkscape #endif -- 2.30.2