effect.cpp revision add2ffae3c4686b50d888775bbdf083a4726a210
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm#define INKSCAPE_LIVEPATHEFFECT_CPP
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm/*
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm * Copyright (C) Johan Engelen 2007 <j.b.c.engelen@utwente.nl>
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm *
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm * Released under GNU GPL, read the file 'COPYING' for more information
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm */
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
ddc251b3cf95b0097b6a5ee39ea132bd4d7d5cbcjohanengelen#include "live_effects/effect.h"
ddc251b3cf95b0097b6a5ee39ea132bd4d7d5cbcjohanengelen
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm#include "display/display-forward.h"
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm#include "xml/node-event-vector.h"
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm#include "sp-object.h"
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm#include "attributes.h"
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm#include "message-stack.h"
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm#include "desktop.h"
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm#include "inkscape.h"
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm#include "document.h"
6656f193fdace606d1b162d6dea0223bc295f0a6cilix#include "document-private.h"
6656f193fdace606d1b162d6dea0223bc295f0a6cilix#include "xml/document.h"
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm#include <glibmm/i18n.h>
77a4a003111bd5cfb771d4849801c898aeb889b0cilix#include "pen-context.h"
77a4a003111bd5cfb771d4849801c898aeb889b0cilix#include "tools-switch.h"
04c99c338ffdc6e10cb6f5c18f6f06b3f555e8ebcilix#include "message-stack.h"
04c99c338ffdc6e10cb6f5c18f6f06b3f555e8ebcilix#include "desktop.h"
04c99c338ffdc6e10cb6f5c18f6f06b3f555e8ebcilix#include "nodepath.h"
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm#include "live_effects/lpeobject.h"
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm#include "live_effects/parameter/parameter.h"
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm#include <glibmm/ustring.h>
d9c673867f424647c1586c356cc0ac1d34d0a98ajohanengelen#include "libnr/n-art-bpath-2geom.h"
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm#include "display/curve.h"
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm#include <gtkmm.h>
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm#include <exception>
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
ddc251b3cf95b0097b6a5ee39ea132bd4d7d5cbcjohanengelen#include <2geom/sbasis-to-bezier.h>
ddc251b3cf95b0097b6a5ee39ea132bd4d7d5cbcjohanengelen#include <2geom/matrix.h>
ddc251b3cf95b0097b6a5ee39ea132bd4d7d5cbcjohanengelen
ddc251b3cf95b0097b6a5ee39ea132bd4d7d5cbcjohanengelen
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm// include effects:
8c39cbeab9949a0a7d6ae66b768a7352019e42f8johanengelen#include "live_effects/lpe-patternalongpath.h"
072916d0ef7dccd696b59381f50bcf776abccefbjohanengelen#include "live_effects/lpe-bendpath.h"
dc98accfae7a38326b92d74fa4330ac8ccb5b778jfbarraud#include "live_effects/lpe-sketch.h"
dc98accfae7a38326b92d74fa4330ac8ccb5b778jfbarraud#include "live_effects/lpe-vonkoch.h"
dc98accfae7a38326b92d74fa4330ac8ccb5b778jfbarraud#include "live_effects/lpe-knot.h"
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm#include "live_effects/lpe-test-doEffect-stack.h"
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm#include "live_effects/lpe-gears.h"
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm#include "live_effects/lpe-curvestitch.h"
8d9f5d586a04809427ce1df284a5720112177991cilix#include "live_effects/lpe-circle_with_radius.h"
70eb1fc448cb08acf3468f80fa2296c03b32afd2cilix#include "live_effects/lpe-perspective_path.h"
c169f6cddd2da06cfb761339f445bbd8866f72a8buliabyak#include "live_effects/lpe-spiro.h"
0563fd55cbad59e8a878e6d4cbbdd8e47f74488djohanengelen#include "live_effects/lpe-lattice.h"
0cc5b8d2f7b87c4222ee3662071bef1cb1f22b06bgk#include "live_effects/lpe-envelope.h"
0563fd55cbad59e8a878e6d4cbbdd8e47f74488djohanengelen#include "live_effects/lpe-constructgrid.h"
f4db63be4e929f4706410914295deccaceea19cdcilix#include "live_effects/lpe-perp_bisector.h"
ab99111a42436818e6902e044c8f3af2b724263bcilix#include "live_effects/lpe-tangent_to_curve.h"
76db360f5f052775326e6d406b9e1e9e2966e11acilix#include "live_effects/lpe-mirror_symmetry.h"
3d0482af18ffb591c1d8ddecf516629e1bcd2ae4cilix#include "live_effects/lpe-circle_3pts.h"
64aee804a6a47424f7994e60558351b8cf2ea4dbcilix#include "live_effects/lpe-angle_bisector.h"
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix#include "live_effects/lpe-parallel.h"
044d712d4d03f8354962d54e47cfac2346a69ccccilix#include "live_effects/lpe-copy_rotate.h"
61cfd957cd023c4f432ea0c7307784a56bf978e9cilix#include "live_effects/lpe-offset.h"
2f5c0701b333a695eedb1680beb1adf95c0723dacilix#include "live_effects/lpe-ruler.h"
add2ffae3c4686b50d888775bbdf083a4726a210johanengelen#include "live_effects/lpe-boolops.h"
e54ce05030e6aab675331e18f46f029f55ed1bf0cilix// end of includes
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrmnamespace Inkscape {
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrmnamespace LivePathEffect {
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrmconst Util::EnumData<EffectType> LPETypeData[INVALID_LPE] = {
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm // {constant defined in effect.h, N_("name of your effect"), "name of your effect in SVG"}
072916d0ef7dccd696b59381f50bcf776abccefbjohanengelen {BEND_PATH, N_("Bend"), "bend_path"},
8c39cbeab9949a0a7d6ae66b768a7352019e42f8johanengelen {PATTERN_ALONG_PATH, N_("Pattern Along Path"), "skeletal"}, // for historic reasons, this effect is called skeletal(strokes) in Inkscape:SVG
29f9623ba77fc735b89765ae3a13e0c06aabafcecilix {FREEHAND_SHAPE, N_("Freehand Shape"), "freehand_shape"}, // this is actually a special type of PatternAlongPath, used to paste shapes in pen/pencil tool
dc98accfae7a38326b92d74fa4330ac8ccb5b778jfbarraud {SKETCH, N_("Sketch"), "sketch"},
dc98accfae7a38326b92d74fa4330ac8ccb5b778jfbarraud {VONKOCH, N_("VonKoch"), "vonkoch"},
dc98accfae7a38326b92d74fa4330ac8ccb5b778jfbarraud {KNOT, N_("Knot"), "knot"},
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm#ifdef LPE_ENABLE_TEST_EFFECTS
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm {DOEFFECTSTACK_TEST, N_("doEffect stack test"), "doeffectstacktest"},
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm#endif
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm {GEARS, N_("Gears"), "gears"},
0563fd55cbad59e8a878e6d4cbbdd8e47f74488djohanengelen {CURVE_STITCH, N_("Stitch Sub-Paths"), "curvestitching"},
8d9f5d586a04809427ce1df284a5720112177991cilix {CIRCLE_WITH_RADIUS, N_("Circle (center+radius)"), "circle_with_radius"},
70eb1fc448cb08acf3468f80fa2296c03b32afd2cilix {PERSPECTIVE_PATH, N_("Perspective path"), "perspective_path"},
c169f6cddd2da06cfb761339f445bbd8866f72a8buliabyak {SPIRO, N_("Spiro spline"), "spiro"},
0563fd55cbad59e8a878e6d4cbbdd8e47f74488djohanengelen {LATTICE, N_("Lattice Deformation"), "lattice"},
0cc5b8d2f7b87c4222ee3662071bef1cb1f22b06bgk {ENVELOPE, N_("Envelope Deformation"), "envelope"},
0563fd55cbad59e8a878e6d4cbbdd8e47f74488djohanengelen {CONSTRUCT_GRID, N_("Construct grid"), "construct_grid"},
f4db63be4e929f4706410914295deccaceea19cdcilix {PERP_BISECTOR, N_("Perpendicular bisector"), "perp_bisector"},
b0c42c0dfcd02cc05126371948489a5a88b2e4b3cilix {TANGENT_TO_CURVE, N_("Tangent to curve"), "tangent_to_curve"},
76db360f5f052775326e6d406b9e1e9e2966e11acilix {MIRROR_SYMMETRY, N_("Mirror symmetry"), "mirror_symmetry"},
3d0482af18ffb591c1d8ddecf516629e1bcd2ae4cilix {CIRCLE_3PTS, N_("Circle through 3 points"), "circle_3pts"},
64aee804a6a47424f7994e60558351b8cf2ea4dbcilix {ANGLE_BISECTOR, N_("Angle bisector"), "angle_bisector"},
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix {PARALLEL, N_("Parallel"), "parallel"},
044d712d4d03f8354962d54e47cfac2346a69ccccilix {COPY_ROTATE, N_("Rotate copies"), "copy_rotate"},
61cfd957cd023c4f432ea0c7307784a56bf978e9cilix {OFFSET, N_("Offset"), "offset"},
2f5c0701b333a695eedb1680beb1adf95c0723dacilix {RULER, N_("Ruler"), "ruler"},
add2ffae3c4686b50d888775bbdf083a4726a210johanengelen {BOOLOPS, N_("Boolops"), "boolops"},
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm};
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrmconst Util::EnumDataConverter<EffectType> LPETypeConverter(LPETypeData, INVALID_LPE);
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrmEffect*
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrmEffect::New(EffectType lpenr, LivePathEffectObject *lpeobj)
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm{
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm Effect* neweffect = NULL;
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm switch (lpenr) {
8c39cbeab9949a0a7d6ae66b768a7352019e42f8johanengelen case PATTERN_ALONG_PATH:
92fe3142613d000eff89db8a983b3b18b14eee79johanengelen neweffect = static_cast<Effect*> ( new LPEPatternAlongPath(lpeobj) );
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm break;
29f9623ba77fc735b89765ae3a13e0c06aabafcecilix case FREEHAND_SHAPE:
29f9623ba77fc735b89765ae3a13e0c06aabafcecilix neweffect = static_cast<Effect*> ( new LPEFreehandShape(lpeobj) );
29f9623ba77fc735b89765ae3a13e0c06aabafcecilix break;
072916d0ef7dccd696b59381f50bcf776abccefbjohanengelen case BEND_PATH:
92fe3142613d000eff89db8a983b3b18b14eee79johanengelen neweffect = static_cast<Effect*> ( new LPEBendPath(lpeobj) );
42e99769805c14a5cc01c805faa3c3b03f9dd1c0johanengelen break;
dc98accfae7a38326b92d74fa4330ac8ccb5b778jfbarraud case SKETCH:
92fe3142613d000eff89db8a983b3b18b14eee79johanengelen neweffect = static_cast<Effect*> ( new LPESketch(lpeobj) );
dc98accfae7a38326b92d74fa4330ac8ccb5b778jfbarraud break;
dc98accfae7a38326b92d74fa4330ac8ccb5b778jfbarraud case VONKOCH:
92fe3142613d000eff89db8a983b3b18b14eee79johanengelen neweffect = static_cast<Effect*> ( new LPEVonKoch(lpeobj) );
dc98accfae7a38326b92d74fa4330ac8ccb5b778jfbarraud break;
dc98accfae7a38326b92d74fa4330ac8ccb5b778jfbarraud case KNOT:
92fe3142613d000eff89db8a983b3b18b14eee79johanengelen neweffect = static_cast<Effect*> ( new LPEKnot(lpeobj) );
dc98accfae7a38326b92d74fa4330ac8ccb5b778jfbarraud break;
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm#ifdef LPE_ENABLE_TEST_EFFECTS
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm case DOEFFECTSTACK_TEST:
92fe3142613d000eff89db8a983b3b18b14eee79johanengelen neweffect = static_cast<Effect*> ( new LPEdoEffectStackTest(lpeobj) );
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm break;
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm#endif
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm case GEARS:
92fe3142613d000eff89db8a983b3b18b14eee79johanengelen neweffect = static_cast<Effect*> ( new LPEGears(lpeobj) );
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm break;
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm case CURVE_STITCH:
92fe3142613d000eff89db8a983b3b18b14eee79johanengelen neweffect = static_cast<Effect*> ( new LPECurveStitch(lpeobj) );
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm break;
0563fd55cbad59e8a878e6d4cbbdd8e47f74488djohanengelen case LATTICE:
0563fd55cbad59e8a878e6d4cbbdd8e47f74488djohanengelen neweffect = static_cast<Effect*> ( new LPELattice(lpeobj) );
0563fd55cbad59e8a878e6d4cbbdd8e47f74488djohanengelen break;
0563fd55cbad59e8a878e6d4cbbdd8e47f74488djohanengelen case ENVELOPE:
0563fd55cbad59e8a878e6d4cbbdd8e47f74488djohanengelen neweffect = static_cast<Effect*> ( new LPEEnvelope(lpeobj) );
0563fd55cbad59e8a878e6d4cbbdd8e47f74488djohanengelen break;
8d9f5d586a04809427ce1df284a5720112177991cilix case CIRCLE_WITH_RADIUS:
92fe3142613d000eff89db8a983b3b18b14eee79johanengelen neweffect = static_cast<Effect*> ( new LPECircleWithRadius(lpeobj) );
8d9f5d586a04809427ce1df284a5720112177991cilix break;
70eb1fc448cb08acf3468f80fa2296c03b32afd2cilix case PERSPECTIVE_PATH:
92fe3142613d000eff89db8a983b3b18b14eee79johanengelen neweffect = static_cast<Effect*> ( new LPEPerspectivePath(lpeobj) );
70eb1fc448cb08acf3468f80fa2296c03b32afd2cilix break;
c169f6cddd2da06cfb761339f445bbd8866f72a8buliabyak case SPIRO:
c169f6cddd2da06cfb761339f445bbd8866f72a8buliabyak neweffect = static_cast<Effect*> ( new LPESpiro(lpeobj) );
c169f6cddd2da06cfb761339f445bbd8866f72a8buliabyak break;
6f4a90e526af850ffc36064f58f09c190f3b633fjohanengelen case CONSTRUCT_GRID:
6f4a90e526af850ffc36064f58f09c190f3b633fjohanengelen neweffect = static_cast<Effect*> ( new LPEConstructGrid(lpeobj) );
6f4a90e526af850ffc36064f58f09c190f3b633fjohanengelen break;
f4db63be4e929f4706410914295deccaceea19cdcilix case PERP_BISECTOR:
f4db63be4e929f4706410914295deccaceea19cdcilix neweffect = static_cast<Effect*> ( new LPEPerpBisector(lpeobj) );
f4db63be4e929f4706410914295deccaceea19cdcilix break;
ab99111a42436818e6902e044c8f3af2b724263bcilix case TANGENT_TO_CURVE:
ab99111a42436818e6902e044c8f3af2b724263bcilix neweffect = static_cast<Effect*> ( new LPETangentToCurve(lpeobj) );
ab99111a42436818e6902e044c8f3af2b724263bcilix break;
76db360f5f052775326e6d406b9e1e9e2966e11acilix case MIRROR_SYMMETRY:
76db360f5f052775326e6d406b9e1e9e2966e11acilix neweffect = static_cast<Effect*> ( new LPEMirrorSymmetry(lpeobj) );
b0c42c0dfcd02cc05126371948489a5a88b2e4b3cilix break;
3d0482af18ffb591c1d8ddecf516629e1bcd2ae4cilix case CIRCLE_3PTS:
3d0482af18ffb591c1d8ddecf516629e1bcd2ae4cilix neweffect = static_cast<Effect*> ( new LPECircle3Pts(lpeobj) );
3d0482af18ffb591c1d8ddecf516629e1bcd2ae4cilix break;
64aee804a6a47424f7994e60558351b8cf2ea4dbcilix case ANGLE_BISECTOR:
64aee804a6a47424f7994e60558351b8cf2ea4dbcilix neweffect = static_cast<Effect*> ( new LPEAngleBisector(lpeobj) );
64aee804a6a47424f7994e60558351b8cf2ea4dbcilix break;
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix case PARALLEL:
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix neweffect = static_cast<Effect*> ( new LPEParallel(lpeobj) );
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix break;
044d712d4d03f8354962d54e47cfac2346a69ccccilix case COPY_ROTATE:
044d712d4d03f8354962d54e47cfac2346a69ccccilix neweffect = static_cast<Effect*> ( new LPECopyRotate(lpeobj) );
044d712d4d03f8354962d54e47cfac2346a69ccccilix break;
61cfd957cd023c4f432ea0c7307784a56bf978e9cilix case OFFSET:
61cfd957cd023c4f432ea0c7307784a56bf978e9cilix neweffect = static_cast<Effect*> ( new LPEOffset(lpeobj) );
61cfd957cd023c4f432ea0c7307784a56bf978e9cilix break;
2f5c0701b333a695eedb1680beb1adf95c0723dacilix case RULER:
2f5c0701b333a695eedb1680beb1adf95c0723dacilix neweffect = static_cast<Effect*> ( new LPERuler(lpeobj) );
2f5c0701b333a695eedb1680beb1adf95c0723dacilix break;
add2ffae3c4686b50d888775bbdf083a4726a210johanengelen case BOOLOPS:
add2ffae3c4686b50d888775bbdf083a4726a210johanengelen neweffect = static_cast<Effect*> ( new LPEBoolops(lpeobj) );
add2ffae3c4686b50d888775bbdf083a4726a210johanengelen break;
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm default:
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm g_warning("LivePathEffect::Effect::New called with invalid patheffect type (%d)", lpenr);
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm neweffect = NULL;
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm break;
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm }
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm if (neweffect) {
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm neweffect->readallParameters(SP_OBJECT_REPR(lpeobj));
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm }
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm return neweffect;
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm}
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
6656f193fdace606d1b162d6dea0223bc295f0a6cilixvoid
6656f193fdace606d1b162d6dea0223bc295f0a6cilixEffect::createAndApply(const char* name, SPDocument *doc, SPItem *item)
6656f193fdace606d1b162d6dea0223bc295f0a6cilix{
6656f193fdace606d1b162d6dea0223bc295f0a6cilix // Path effect definition
6656f193fdace606d1b162d6dea0223bc295f0a6cilix Inkscape::XML::Document *xml_doc = sp_document_repr_doc(doc);
6656f193fdace606d1b162d6dea0223bc295f0a6cilix Inkscape::XML::Node *repr = xml_doc->createElement("inkscape:path-effect");
6656f193fdace606d1b162d6dea0223bc295f0a6cilix repr->setAttribute("effect", name);
6656f193fdace606d1b162d6dea0223bc295f0a6cilix
6656f193fdace606d1b162d6dea0223bc295f0a6cilix SP_OBJECT_REPR(SP_DOCUMENT_DEFS(doc))->addChild(repr, NULL); // adds to <defs> and assigns the 'id' attribute
6656f193fdace606d1b162d6dea0223bc295f0a6cilix const gchar * repr_id = repr->attribute("id");
6656f193fdace606d1b162d6dea0223bc295f0a6cilix Inkscape::GC::release(repr);
6656f193fdace606d1b162d6dea0223bc295f0a6cilix
6656f193fdace606d1b162d6dea0223bc295f0a6cilix gchar *href = g_strdup_printf("#%s", repr_id);
6656f193fdace606d1b162d6dea0223bc295f0a6cilix sp_lpe_item_add_path_effect(SP_LPE_ITEM(item), href, true);
6656f193fdace606d1b162d6dea0223bc295f0a6cilix g_free(href);
6656f193fdace606d1b162d6dea0223bc295f0a6cilix}
6656f193fdace606d1b162d6dea0223bc295f0a6cilix
6656f193fdace606d1b162d6dea0223bc295f0a6cilixvoid
6656f193fdace606d1b162d6dea0223bc295f0a6cilixEffect::createAndApply(EffectType type, SPDocument *doc, SPItem *item)
6656f193fdace606d1b162d6dea0223bc295f0a6cilix{
6656f193fdace606d1b162d6dea0223bc295f0a6cilix createAndApply(LPETypeConverter.get_key(type).c_str(), doc, item);
6656f193fdace606d1b162d6dea0223bc295f0a6cilix}
6656f193fdace606d1b162d6dea0223bc295f0a6cilix
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrmEffect::Effect(LivePathEffectObject *lpeobject)
fbb4eb8b63e74d9441220a73a8ca858425be4bd4johanengelen : oncanvasedit_it(0),
71146abe8aba032d73788a625fee5769a581bd3ccilix is_visible(_("Is visible?"), _("If unchecked, the effect remains applied to the object but is temporarily disabled on canvas"), "is_visible", &wr, this, true),
77a4a003111bd5cfb771d4849801c898aeb889b0cilix done_pathparam_set(false),
04c99c338ffdc6e10cb6f5c18f6f06b3f555e8ebcilix show_orig_path(false),
fbb4eb8b63e74d9441220a73a8ca858425be4bd4johanengelen lpeobj(lpeobject),
9ce14357bb94b9dd92ad40bf43ef435a257b355acilix concatenate_before_pwd2(false),
9ce14357bb94b9dd92ad40bf43ef435a257b355acilix provides_own_flash_paths(true) // is automatically set to false if providesOwnFlashPaths() is not overridden
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm{
71146abe8aba032d73788a625fee5769a581bd3ccilix registerParameter( dynamic_cast<Parameter *>(&is_visible) );
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm}
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrmEffect::~Effect()
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm{
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm}
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
eaa9bdc7bf7b73397e536edd47490d84e4420bd8bryceGlib::ustring
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrmEffect::getName()
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm{
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm if (lpeobj->effecttype_set && lpeobj->effecttype < INVALID_LPE)
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm return Glib::ustring( _(LPETypeConverter.get_label(lpeobj->effecttype).c_str()) );
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm else
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm return Glib::ustring( _("No effect") );
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm}
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
c90010388b0d4045c26e81c2be28beedcb36c7d3cilixEffectType
c90010388b0d4045c26e81c2be28beedcb36c7d3cilixEffect::effectType() {
c90010388b0d4045c26e81c2be28beedcb36c7d3cilix return lpeobj->effecttype;
c90010388b0d4045c26e81c2be28beedcb36c7d3cilix}
c90010388b0d4045c26e81c2be28beedcb36c7d3cilix
77a4a003111bd5cfb771d4849801c898aeb889b0cilix/**
77a4a003111bd5cfb771d4849801c898aeb889b0cilix * Is performed a single time when the effect is freshly applied to a path
77a4a003111bd5cfb771d4849801c898aeb889b0cilix */
262d0c3f05130d86368d95f110aa8ccab5f83e5ccilixvoid
262d0c3f05130d86368d95f110aa8ccab5f83e5ccilixEffect::doOnApply (SPLPEItem */*lpeitem*/)
262d0c3f05130d86368d95f110aa8ccab5f83e5ccilix{
262d0c3f05130d86368d95f110aa8ccab5f83e5ccilix}
262d0c3f05130d86368d95f110aa8ccab5f83e5ccilix
77a4a003111bd5cfb771d4849801c898aeb889b0cilix/**
77a4a003111bd5cfb771d4849801c898aeb889b0cilix * Is performed each time before the effect is updated.
77a4a003111bd5cfb771d4849801c898aeb889b0cilix */
23d859f2ce09c04ed802cb4912cc9c50f512f0a2bgkvoid
2d107ef9730aff3f4d776ae0c2f7d983e289ce02joncruzEffect::doBeforeEffect (SPLPEItem */*lpeitem*/)
23d859f2ce09c04ed802cb4912cc9c50f512f0a2bgk{
23d859f2ce09c04ed802cb4912cc9c50f512f0a2bgk //Do nothing for simple effects
23d859f2ce09c04ed802cb4912cc9c50f512f0a2bgk}
23d859f2ce09c04ed802cb4912cc9c50f512f0a2bgk
77a4a003111bd5cfb771d4849801c898aeb889b0cilix/**
147c8e03bb214f85cd5906ddc6413c4293c4baa9cilix * Effects can have a parameter path set before they are applied by accepting a nonzero number of
147c8e03bb214f85cd5906ddc6413c4293c4baa9cilix * mouse clicks. This method activates the pen context, which waits for the specified number of
147c8e03bb214f85cd5906ddc6413c4293c4baa9cilix * clicks. Override Effect::acceptsNumParams() to return the number of expected mouse clicks.
77a4a003111bd5cfb771d4849801c898aeb889b0cilix */
77a4a003111bd5cfb771d4849801c898aeb889b0cilixvoid
77a4a003111bd5cfb771d4849801c898aeb889b0cilixEffect::doAcceptPathPreparations(SPLPEItem *lpeitem)
77a4a003111bd5cfb771d4849801c898aeb889b0cilix{
77a4a003111bd5cfb771d4849801c898aeb889b0cilix // switch to pen context
77a4a003111bd5cfb771d4849801c898aeb889b0cilix SPDesktop *desktop = inkscape_active_desktop(); // TODO: Is there a better method to find the item's desktop?
77a4a003111bd5cfb771d4849801c898aeb889b0cilix if (!tools_isactive(desktop, TOOLS_FREEHAND_PEN)) {
77a4a003111bd5cfb771d4849801c898aeb889b0cilix tools_switch(desktop, TOOLS_FREEHAND_PEN);
77a4a003111bd5cfb771d4849801c898aeb889b0cilix }
77a4a003111bd5cfb771d4849801c898aeb889b0cilix
77a4a003111bd5cfb771d4849801c898aeb889b0cilix SPEventContext *ec = desktop->event_context;
77a4a003111bd5cfb771d4849801c898aeb889b0cilix SPPenContext *pc = SP_PEN_CONTEXT(ec);
77a4a003111bd5cfb771d4849801c898aeb889b0cilix pc->expecting_clicks_for_LPE = this->acceptsNumParams();
77a4a003111bd5cfb771d4849801c898aeb889b0cilix pc->waiting_LPE = this;
77a4a003111bd5cfb771d4849801c898aeb889b0cilix pc->waiting_item = lpeitem;
77a4a003111bd5cfb771d4849801c898aeb889b0cilix pc->polylines_only = true;
77a4a003111bd5cfb771d4849801c898aeb889b0cilix
77a4a003111bd5cfb771d4849801c898aeb889b0cilix ec->desktop->messageStack()->flash(Inkscape::INFORMATION_MESSAGE,
77a4a003111bd5cfb771d4849801c898aeb889b0cilix g_strdup_printf(_("Please specify a parameter path for the LPE '%s' with %d mouse clicks"),
77a4a003111bd5cfb771d4849801c898aeb889b0cilix getName().c_str(), acceptsNumParams()));
77a4a003111bd5cfb771d4849801c898aeb889b0cilix}
23d859f2ce09c04ed802cb4912cc9c50f512f0a2bgk
97a20864afec63a0b7bb757b628ee2ae596cf648cilixvoid
97a20864afec63a0b7bb757b628ee2ae596cf648cilixEffect::writeParamsToSVG() {
97a20864afec63a0b7bb757b628ee2ae596cf648cilix std::vector<Inkscape::LivePathEffect::Parameter *>::iterator p;
97a20864afec63a0b7bb757b628ee2ae596cf648cilix for (p = param_vector.begin(); p != param_vector.end(); ++p) {
97a20864afec63a0b7bb757b628ee2ae596cf648cilix (*p)->write_to_SVG();
97a20864afec63a0b7bb757b628ee2ae596cf648cilix }
97a20864afec63a0b7bb757b628ee2ae596cf648cilix}
97a20864afec63a0b7bb757b628ee2ae596cf648cilix
77a4a003111bd5cfb771d4849801c898aeb889b0cilix/**
77a4a003111bd5cfb771d4849801c898aeb889b0cilix * If the effect expects a path parameter (specified by a number of mouse clicks) before it is
77a4a003111bd5cfb771d4849801c898aeb889b0cilix * applied, this is the method that processes the resulting path. Override it to customize it for
77a4a003111bd5cfb771d4849801c898aeb889b0cilix * your LPE. But don't forget to call the parent method so that done_pathparam_set is set to true!
77a4a003111bd5cfb771d4849801c898aeb889b0cilix */
77a4a003111bd5cfb771d4849801c898aeb889b0cilixvoid
2d2706a9d621c0da51b7c4178fd5c7c5e4765122joncruzEffect::acceptParamPath (SPPath */*param_path*/) {
77a4a003111bd5cfb771d4849801c898aeb889b0cilix done_pathparam_set = true;
77a4a003111bd5cfb771d4849801c898aeb889b0cilix}
77a4a003111bd5cfb771d4849801c898aeb889b0cilix
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm/*
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm * Here be the doEffect function chain:
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm */
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrmvoid
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrmEffect::doEffect (SPCurve * curve)
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm{
b802808a0226a87371021393c4f1da776aa6a6adjohanengelen std::vector<Geom::Path> orig_pathv = curve->get_pathvector();
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
b802808a0226a87371021393c4f1da776aa6a6adjohanengelen std::vector<Geom::Path> result_pathv = doEffect_path(orig_pathv);
dda97aeba7480d08320ebceecae13b8531db1b81johanengelen
a2fbdfc8e80d3d1845bf0d5df989726ae2ffd5bfjohanengelen curve->set_pathvector(result_pathv);
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm}
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrmstd::vector<Geom::Path>
ecda720053ff791e35dae3c5c1177bc225b6cdf1johanengelenEffect::doEffect_path (std::vector<Geom::Path> const & path_in)
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm{
46c4893a7458eda6edcd064121bc000634af7a09johanengelen std::vector<Geom::Path> path_out;
46c4893a7458eda6edcd064121bc000634af7a09johanengelen
46c4893a7458eda6edcd064121bc000634af7a09johanengelen if ( !concatenate_before_pwd2 ) {
46c4893a7458eda6edcd064121bc000634af7a09johanengelen // default behavior
46c4893a7458eda6edcd064121bc000634af7a09johanengelen for (unsigned int i=0; i < path_in.size(); i++) {
46c4893a7458eda6edcd064121bc000634af7a09johanengelen Geom::Piecewise<Geom::D2<Geom::SBasis> > pwd2_in = path_in[i].toPwSb();
46c4893a7458eda6edcd064121bc000634af7a09johanengelen Geom::Piecewise<Geom::D2<Geom::SBasis> > pwd2_out = doEffect_pwd2(pwd2_in);
46c4893a7458eda6edcd064121bc000634af7a09johanengelen std::vector<Geom::Path> path = Geom::path_from_piecewise( pwd2_out, LPE_CONVERSION_TOLERANCE);
46c4893a7458eda6edcd064121bc000634af7a09johanengelen // add the output path vector to the already accumulated vector:
46c4893a7458eda6edcd064121bc000634af7a09johanengelen for (unsigned int j=0; j < path.size(); j++) {
46c4893a7458eda6edcd064121bc000634af7a09johanengelen path_out.push_back(path[j]);
46c4893a7458eda6edcd064121bc000634af7a09johanengelen }
46c4893a7458eda6edcd064121bc000634af7a09johanengelen }
46c4893a7458eda6edcd064121bc000634af7a09johanengelen } else {
46c4893a7458eda6edcd064121bc000634af7a09johanengelen // concatenate the path into possibly discontinuous pwd2
46c4893a7458eda6edcd064121bc000634af7a09johanengelen Geom::Piecewise<Geom::D2<Geom::SBasis> > pwd2_in;
46c4893a7458eda6edcd064121bc000634af7a09johanengelen for (unsigned int i=0; i < path_in.size(); i++) {
46c4893a7458eda6edcd064121bc000634af7a09johanengelen pwd2_in.concat( path_in[i].toPwSb() );
46c4893a7458eda6edcd064121bc000634af7a09johanengelen }
46c4893a7458eda6edcd064121bc000634af7a09johanengelen Geom::Piecewise<Geom::D2<Geom::SBasis> > pwd2_out = doEffect_pwd2(pwd2_in);
46c4893a7458eda6edcd064121bc000634af7a09johanengelen path_out = Geom::path_from_piecewise( pwd2_out, LPE_CONVERSION_TOLERANCE);
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm }
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm return path_out;
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm}
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrmGeom::Piecewise<Geom::D2<Geom::SBasis> >
ecda720053ff791e35dae3c5c1177bc225b6cdf1johanengelenEffect::doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwd2_in)
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm{
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm g_warning("Effect has no doEffect implementation");
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm return pwd2_in;
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm}
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrmvoid
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrmEffect::readallParameters(Inkscape::XML::Node * repr)
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm{
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelen std::vector<Parameter *>::iterator it = param_vector.begin();
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelen while (it != param_vector.end()) {
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelen Parameter * param = *it;
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelen const gchar * key = param->param_key.c_str();
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm const gchar * value = repr->attribute(key);
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelen if (value) {
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelen bool accepted = param->param_readSVGValue(value);
2d107ef9730aff3f4d776ae0c2f7d983e289ce02joncruz if (!accepted) {
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelen g_warning("Effect::readallParameters - '%s' not accepted for %s", value, key);
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelen }
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelen } else {
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelen // set default value
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelen param->param_set_default();
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm }
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelen
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm it++;
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm }
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm}
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
0fc5ce7045233dae7e15fdc86774370f1b1d73cbjohanengelen/* This function does not and SHOULD NOT write to XML */
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrmvoid
0fc5ce7045233dae7e15fdc86774370f1b1d73cbjohanengelenEffect::setParameter(const gchar * key, const gchar * new_value)
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm{
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelen Parameter * param = getParameter(key);
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelen if (param) {
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm if (new_value) {
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelen bool accepted = param->param_readSVGValue(new_value);
2d107ef9730aff3f4d776ae0c2f7d983e289ce02joncruz if (!accepted) {
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm g_warning("Effect::setParameter - '%s' not accepted for %s", new_value, key);
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm }
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm } else {
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm // set default value
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelen param->param_set_default();
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm }
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm }
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm}
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrmvoid
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrmEffect::registerParameter(Parameter * param)
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm{
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelen param_vector.push_back(param);
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm}
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
5be124ad592f5c71eca838ad2eaac9ffa953605fcilix// TODO: should we provide a way to alter the handle's appearance?
73d455c08e8062e257dd052d2d690b9300434351cilixvoid
5be124ad592f5c71eca838ad2eaac9ffa953605fcilixEffect::registerKnotHolderHandle(KnotHolderEntity* entity, const char* descr)
73d455c08e8062e257dd052d2d690b9300434351cilix{
5be124ad592f5c71eca838ad2eaac9ffa953605fcilix kh_entity_vector.push_back(std::make_pair(entity, descr));
5be124ad592f5c71eca838ad2eaac9ffa953605fcilix}
5be124ad592f5c71eca838ad2eaac9ffa953605fcilix
5be124ad592f5c71eca838ad2eaac9ffa953605fcilix/**
5be124ad592f5c71eca838ad2eaac9ffa953605fcilix * Add all registered LPE knotholder handles to the knotholder
5be124ad592f5c71eca838ad2eaac9ffa953605fcilix */
5be124ad592f5c71eca838ad2eaac9ffa953605fcilixvoid
5be124ad592f5c71eca838ad2eaac9ffa953605fcilixEffect::addHandles(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item) {
5be124ad592f5c71eca838ad2eaac9ffa953605fcilix std::vector<std::pair<KnotHolderEntity*, const char*> >::iterator i;
5be124ad592f5c71eca838ad2eaac9ffa953605fcilix for (i = kh_entity_vector.begin(); i != kh_entity_vector.end(); ++i) {
5be124ad592f5c71eca838ad2eaac9ffa953605fcilix KnotHolderEntity *entity = i->first;
5be124ad592f5c71eca838ad2eaac9ffa953605fcilix const char *descr = i->second;
5be124ad592f5c71eca838ad2eaac9ffa953605fcilix
5be124ad592f5c71eca838ad2eaac9ffa953605fcilix entity->create(desktop, item, knotholder, descr);
5be124ad592f5c71eca838ad2eaac9ffa953605fcilix knotholder->add(entity);
5be124ad592f5c71eca838ad2eaac9ffa953605fcilix }
73d455c08e8062e257dd052d2d690b9300434351cilix}
73d455c08e8062e257dd052d2d690b9300434351cilix
73d455c08e8062e257dd052d2d690b9300434351cilixvoid
1e944d29efb206f5d0b5d1069cb098e22169d548cilixEffect::addPointParamHandles(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item) {
79d46cc367c4181803d9a7a327b163643f23e8a7cilix using namespace Inkscape::LivePathEffect;
1e944d29efb206f5d0b5d1069cb098e22169d548cilix for (std::vector<Parameter *>::iterator p = param_vector.begin(); p != param_vector.end(); ++p) {
79d46cc367c4181803d9a7a327b163643f23e8a7cilix if ((*p)->paramType() == POINT_PARAM) {
79d46cc367c4181803d9a7a327b163643f23e8a7cilix PointParam *pparam = static_cast<PointParam *>(*p);
1e944d29efb206f5d0b5d1069cb098e22169d548cilix KnotHolderEntity *e = dynamic_cast<KnotHolderEntity *>(*p);
5ce8d034d9fe78f969629cfe65d1a2518f173ba9cilix e->create(desktop, item, knotholder, pparam->handleTip(),
5ce8d034d9fe78f969629cfe65d1a2518f173ba9cilix pparam->knotShape(), pparam->knotMode(), pparam->knotColor());
1e944d29efb206f5d0b5d1069cb098e22169d548cilix knotholder->add(e);
1e944d29efb206f5d0b5d1069cb098e22169d548cilix }
73d455c08e8062e257dd052d2d690b9300434351cilix }
73d455c08e8062e257dd052d2d690b9300434351cilix}
73d455c08e8062e257dd052d2d690b9300434351cilix
04c99c338ffdc6e10cb6f5c18f6f06b3f555e8ebcilixvoid
04c99c338ffdc6e10cb6f5c18f6f06b3f555e8ebcilixEffect::addHelperPaths(SPLPEItem *lpeitem, SPDesktop *desktop)
04c99c338ffdc6e10cb6f5c18f6f06b3f555e8ebcilix{
147c8e03bb214f85cd5906ddc6413c4293c4baa9cilix g_return_if_fail(desktop);
04c99c338ffdc6e10cb6f5c18f6f06b3f555e8ebcilix g_return_if_fail(SP_IS_PATH(lpeitem));
04c99c338ffdc6e10cb6f5c18f6f06b3f555e8ebcilix
bb78cf2c3a2ee8ea2c98433128556847f03f5799cilix if (providesKnotholder() && showOrigPath()) {
bb78cf2c3a2ee8ea2c98433128556847f03f5799cilix // TODO: we assume that if the LPE provides its own knotholder, there is no nodepath so we
147c8e03bb214f85cd5906ddc6413c4293c4baa9cilix // must create the helper curve for the original path manually; once we allow nodepaths and
bb78cf2c3a2ee8ea2c98433128556847f03f5799cilix // knotholders alongside each other, this needs to be rethought!
04c99c338ffdc6e10cb6f5c18f6f06b3f555e8ebcilix SPCanvasItem *canvasitem = sp_nodepath_generate_helperpath(desktop, SP_PATH(lpeitem));
04c99c338ffdc6e10cb6f5c18f6f06b3f555e8ebcilix Inkscape::Display::TemporaryItem* tmpitem = desktop->add_temporary_canvasitem (canvasitem, 0);
04c99c338ffdc6e10cb6f5c18f6f06b3f555e8ebcilix lpeitem->lpe_helperpaths.push_back(tmpitem);
04c99c338ffdc6e10cb6f5c18f6f06b3f555e8ebcilix }
bb78cf2c3a2ee8ea2c98433128556847f03f5799cilix
732fb09f9c502000068a77667c3356cbbd5d39d5cilix for (std::vector<Parameter *>::iterator p = param_vector.begin(); p != param_vector.end(); ++p) {
732fb09f9c502000068a77667c3356cbbd5d39d5cilix if ((*p)->paramType() == Inkscape::LivePathEffect::PATH_PARAM) {
732fb09f9c502000068a77667c3356cbbd5d39d5cilix SPCurve *c = new SPCurve(static_cast<Inkscape::LivePathEffect::PathParam*>(*p)->get_pathvector());
732fb09f9c502000068a77667c3356cbbd5d39d5cilix
732fb09f9c502000068a77667c3356cbbd5d39d5cilix // TODO: factor this out (also the copied code above); see also lpe-lattice.cpp
732fb09f9c502000068a77667c3356cbbd5d39d5cilix SPCanvasItem *canvasitem = sp_nodepath_generate_helperpath(desktop, c, SP_ITEM(lpeitem), 0x009000ff);
732fb09f9c502000068a77667c3356cbbd5d39d5cilix Inkscape::Display::TemporaryItem* tmpitem = desktop->add_temporary_canvasitem (canvasitem, 0);
732fb09f9c502000068a77667c3356cbbd5d39d5cilix lpeitem->lpe_helperpaths.push_back(tmpitem);
732fb09f9c502000068a77667c3356cbbd5d39d5cilix }
732fb09f9c502000068a77667c3356cbbd5d39d5cilix }
732fb09f9c502000068a77667c3356cbbd5d39d5cilix
04c99c338ffdc6e10cb6f5c18f6f06b3f555e8ebcilix addHelperPathsImpl(lpeitem, desktop);
04c99c338ffdc6e10cb6f5c18f6f06b3f555e8ebcilix}
04c99c338ffdc6e10cb6f5c18f6f06b3f555e8ebcilix
04c99c338ffdc6e10cb6f5c18f6f06b3f555e8ebcilixvoid
2d2706a9d621c0da51b7c4178fd5c7c5e4765122joncruzEffect::addHelperPathsImpl(SPLPEItem */*lpeitem*/, SPDesktop */*desktop*/)
04c99c338ffdc6e10cb6f5c18f6f06b3f555e8ebcilix{
04c99c338ffdc6e10cb6f5c18f6f06b3f555e8ebcilix // if this method is overloaded in derived classes, provides_own_flash_paths will be true
04c99c338ffdc6e10cb6f5c18f6f06b3f555e8ebcilix provides_own_flash_paths = false;
04c99c338ffdc6e10cb6f5c18f6f06b3f555e8ebcilix}
04c99c338ffdc6e10cb6f5c18f6f06b3f555e8ebcilix
c0cd5511d3b975ebe07d019c1f5528108725e438johanengelen/**
73d455c08e8062e257dd052d2d690b9300434351cilix * This *creates* a new widget, management of deletion should be done by the caller
73d455c08e8062e257dd052d2d690b9300434351cilix */
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrmGtk::Widget *
c0cd5511d3b975ebe07d019c1f5528108725e438johanengelenEffect::newWidget(Gtk::Tooltips * tooltips)
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm{
c0cd5511d3b975ebe07d019c1f5528108725e438johanengelen // use manage here, because after deletion of Effect object, others might still be pointing to this widget.
c0cd5511d3b975ebe07d019c1f5528108725e438johanengelen Gtk::VBox * vbox = Gtk::manage( new Gtk::VBox() );
c0cd5511d3b975ebe07d019c1f5528108725e438johanengelen
c0cd5511d3b975ebe07d019c1f5528108725e438johanengelen vbox->set_border_width(5);
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
c0cd5511d3b975ebe07d019c1f5528108725e438johanengelen std::vector<Parameter *>::iterator it = param_vector.begin();
c0cd5511d3b975ebe07d019c1f5528108725e438johanengelen while (it != param_vector.end()) {
c0cd5511d3b975ebe07d019c1f5528108725e438johanengelen Parameter * param = *it;
c0cd5511d3b975ebe07d019c1f5528108725e438johanengelen Gtk::Widget * widg = param->param_newWidget(tooltips);
c0cd5511d3b975ebe07d019c1f5528108725e438johanengelen Glib::ustring * tip = param->param_getTooltip();
c0cd5511d3b975ebe07d019c1f5528108725e438johanengelen if (widg) {
c0cd5511d3b975ebe07d019c1f5528108725e438johanengelen vbox->pack_start(*widg, true, true, 2);
c0cd5511d3b975ebe07d019c1f5528108725e438johanengelen if (tip != NULL) {
c0cd5511d3b975ebe07d019c1f5528108725e438johanengelen tooltips->set_tip(*widg, *tip);
c0cd5511d3b975ebe07d019c1f5528108725e438johanengelen }
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm }
c0cd5511d3b975ebe07d019c1f5528108725e438johanengelen
c0cd5511d3b975ebe07d019c1f5528108725e438johanengelen it++;
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm }
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm return dynamic_cast<Gtk::Widget *>(vbox);
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm}
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
56542e2b97ec8826cc692153b0e2d4f5ac8ef913johanengelenInkscape::XML::Node *
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrmEffect::getRepr()
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm{
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm return SP_OBJECT_REPR(lpeobj);
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm}
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
56542e2b97ec8826cc692153b0e2d4f5ac8ef913johanengelenSPDocument *
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrmEffect::getSPDoc()
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm{
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm if (SP_OBJECT_DOCUMENT(lpeobj) == NULL) g_message("Effect::getSPDoc() returns NULL");
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm return SP_OBJECT_DOCUMENT(lpeobj);
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm}
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
56542e2b97ec8826cc692153b0e2d4f5ac8ef913johanengelenParameter *
56542e2b97ec8826cc692153b0e2d4f5ac8ef913johanengelenEffect::getParameter(const char * key)
56542e2b97ec8826cc692153b0e2d4f5ac8ef913johanengelen{
56542e2b97ec8826cc692153b0e2d4f5ac8ef913johanengelen Glib::ustring stringkey(key);
56542e2b97ec8826cc692153b0e2d4f5ac8ef913johanengelen
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelen std::vector<Parameter *>::iterator it = param_vector.begin();
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelen while (it != param_vector.end()) {
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelen Parameter * param = *it;
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelen if ( param->param_key == key) {
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelen return param;
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelen }
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelen
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelen it++;
56542e2b97ec8826cc692153b0e2d4f5ac8ef913johanengelen }
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelen
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelen return NULL;
56542e2b97ec8826cc692153b0e2d4f5ac8ef913johanengelen}
56542e2b97ec8826cc692153b0e2d4f5ac8ef913johanengelen
fb5a72174252e0e79107dcad3bf5a2bbd73e349cjohanengelenParameter *
fb5a72174252e0e79107dcad3bf5a2bbd73e349cjohanengelenEffect::getNextOncanvasEditableParam()
fb5a72174252e0e79107dcad3bf5a2bbd73e349cjohanengelen{
af8d25189f88abf89cdbe0e180e271c94079624fbuliabyak if (param_vector.size() == 0) // no parameters
af8d25189f88abf89cdbe0e180e271c94079624fbuliabyak return NULL;
af8d25189f88abf89cdbe0e180e271c94079624fbuliabyak
fb5a72174252e0e79107dcad3bf5a2bbd73e349cjohanengelen oncanvasedit_it++;
af8d25189f88abf89cdbe0e180e271c94079624fbuliabyak if (oncanvasedit_it >= static_cast<int>(param_vector.size())) {
a0334366488989ef25fb812d7030d298c0917c96johanengelen oncanvasedit_it = 0;
fb5a72174252e0e79107dcad3bf5a2bbd73e349cjohanengelen }
a0334366488989ef25fb812d7030d298c0917c96johanengelen int old_it = oncanvasedit_it;
fb5a72174252e0e79107dcad3bf5a2bbd73e349cjohanengelen
fb5a72174252e0e79107dcad3bf5a2bbd73e349cjohanengelen do {
a0334366488989ef25fb812d7030d298c0917c96johanengelen Parameter * param = param_vector[oncanvasedit_it];
a0334366488989ef25fb812d7030d298c0917c96johanengelen if(param && param->oncanvas_editable) {
fb5a72174252e0e79107dcad3bf5a2bbd73e349cjohanengelen return param;
fb5a72174252e0e79107dcad3bf5a2bbd73e349cjohanengelen } else {
fb5a72174252e0e79107dcad3bf5a2bbd73e349cjohanengelen oncanvasedit_it++;
f9504c822b72a774b910958446fd1e730235b7cbjoncruz if (oncanvasedit_it == static_cast<int>(param_vector.size())) { // loop round the map
a0334366488989ef25fb812d7030d298c0917c96johanengelen oncanvasedit_it = 0;
fb5a72174252e0e79107dcad3bf5a2bbd73e349cjohanengelen }
fb5a72174252e0e79107dcad3bf5a2bbd73e349cjohanengelen }
fb5a72174252e0e79107dcad3bf5a2bbd73e349cjohanengelen } while (oncanvasedit_it != old_it); // iterate until complete loop through map has been made
fb5a72174252e0e79107dcad3bf5a2bbd73e349cjohanengelen
fb5a72174252e0e79107dcad3bf5a2bbd73e349cjohanengelen return NULL;
fb5a72174252e0e79107dcad3bf5a2bbd73e349cjohanengelen}
fb5a72174252e0e79107dcad3bf5a2bbd73e349cjohanengelen
fb5a72174252e0e79107dcad3bf5a2bbd73e349cjohanengelenvoid
fb5a72174252e0e79107dcad3bf5a2bbd73e349cjohanengelenEffect::editNextParamOncanvas(SPItem * item, SPDesktop * desktop)
fb5a72174252e0e79107dcad3bf5a2bbd73e349cjohanengelen{
fb5a72174252e0e79107dcad3bf5a2bbd73e349cjohanengelen if (!desktop) return;
fb5a72174252e0e79107dcad3bf5a2bbd73e349cjohanengelen
fb5a72174252e0e79107dcad3bf5a2bbd73e349cjohanengelen Parameter * param = getNextOncanvasEditableParam();
fb5a72174252e0e79107dcad3bf5a2bbd73e349cjohanengelen if (param) {
fb5a72174252e0e79107dcad3bf5a2bbd73e349cjohanengelen param->param_editOncanvas(item, desktop);
fb5a72174252e0e79107dcad3bf5a2bbd73e349cjohanengelen gchar *message = g_strdup_printf(_("Editing parameter <b>%s</b>."), param->param_label.c_str());
fb5a72174252e0e79107dcad3bf5a2bbd73e349cjohanengelen desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, message);
fb5a72174252e0e79107dcad3bf5a2bbd73e349cjohanengelen g_free(message);
fb5a72174252e0e79107dcad3bf5a2bbd73e349cjohanengelen } else {
fb5a72174252e0e79107dcad3bf5a2bbd73e349cjohanengelen desktop->messageStack()->flash( Inkscape::WARNING_MESSAGE,
fb5a72174252e0e79107dcad3bf5a2bbd73e349cjohanengelen _("None of the applied path effect's parameters can be edited on-canvas.") );
fb5a72174252e0e79107dcad3bf5a2bbd73e349cjohanengelen }
fb5a72174252e0e79107dcad3bf5a2bbd73e349cjohanengelen}
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
42e99769805c14a5cc01c805faa3c3b03f9dd1c0johanengelen/* This function should reset the defaults and is used for example to initialize an effect right after it has been applied to a path
42e99769805c14a5cc01c805faa3c3b03f9dd1c0johanengelen* The nice thing about this is that this function can use knowledge of the original path and set things accordingly for example to the size or origin of the original path!
42e99769805c14a5cc01c805faa3c3b03f9dd1c0johanengelen*/
42e99769805c14a5cc01c805faa3c3b03f9dd1c0johanengelenvoid
42e99769805c14a5cc01c805faa3c3b03f9dd1c0johanengelenEffect::resetDefaults(SPItem * /*item*/)
42e99769805c14a5cc01c805faa3c3b03f9dd1c0johanengelen{
42e99769805c14a5cc01c805faa3c3b03f9dd1c0johanengelen // do nothing for simple effects
42e99769805c14a5cc01c805faa3c3b03f9dd1c0johanengelen}
42e99769805c14a5cc01c805faa3c3b03f9dd1c0johanengelen
56542e2b97ec8826cc692153b0e2d4f5ac8ef913johanengelenvoid
a797dcb8e284cab19f60b3eff93a53a62abda263johanengelenEffect::setup_nodepath(Inkscape::NodePath::Path *np)
56542e2b97ec8826cc692153b0e2d4f5ac8ef913johanengelen{
56542e2b97ec8826cc692153b0e2d4f5ac8ef913johanengelen np->helperpath_rgba = 0xff0000ff;
56542e2b97ec8826cc692153b0e2d4f5ac8ef913johanengelen np->helperpath_width = 1.0;
56542e2b97ec8826cc692153b0e2d4f5ac8ef913johanengelen}
56542e2b97ec8826cc692153b0e2d4f5ac8ef913johanengelen
ddc251b3cf95b0097b6a5ee39ea132bd4d7d5cbcjohanengelenvoid
ddc251b3cf95b0097b6a5ee39ea132bd4d7d5cbcjohanengelenEffect::transform_multiply(Geom::Matrix const& postmul, bool set)
ddc251b3cf95b0097b6a5ee39ea132bd4d7d5cbcjohanengelen{
ddc251b3cf95b0097b6a5ee39ea132bd4d7d5cbcjohanengelen // cycle through all parameters. Most parameters will not need transformation, but path and point params do.
ddc251b3cf95b0097b6a5ee39ea132bd4d7d5cbcjohanengelen for (std::vector<Parameter *>::iterator it = param_vector.begin(); it != param_vector.end(); it++) {
ddc251b3cf95b0097b6a5ee39ea132bd4d7d5cbcjohanengelen Parameter * param = *it;
bdd7add6c064afee52d2eabeaa18f745430e5a4djohanengelen param->param_transform_multiply(postmul, set);
ddc251b3cf95b0097b6a5ee39ea132bd4d7d5cbcjohanengelen }
ddc251b3cf95b0097b6a5ee39ea132bd4d7d5cbcjohanengelen}
42e99769805c14a5cc01c805faa3c3b03f9dd1c0johanengelen
42ba1b712b7b430669fc49aa9facb439181081becilixbool
42ba1b712b7b430669fc49aa9facb439181081becilixEffect::providesKnotholder()
42ba1b712b7b430669fc49aa9facb439181081becilix{
42ba1b712b7b430669fc49aa9facb439181081becilix // does the effect actively provide any knotholder entities of its own?
42ba1b712b7b430669fc49aa9facb439181081becilix if (kh_entity_vector.size() > 0)
42ba1b712b7b430669fc49aa9facb439181081becilix return true;
42ba1b712b7b430669fc49aa9facb439181081becilix
42ba1b712b7b430669fc49aa9facb439181081becilix // otherwise: are there any PointParams?
42ba1b712b7b430669fc49aa9facb439181081becilix for (std::vector<Parameter *>::iterator p = param_vector.begin(); p != param_vector.end(); ++p) {
42ba1b712b7b430669fc49aa9facb439181081becilix if ((*p)->paramType() == Inkscape::LivePathEffect::POINT_PARAM) {
42ba1b712b7b430669fc49aa9facb439181081becilix return true;
42ba1b712b7b430669fc49aa9facb439181081becilix }
42ba1b712b7b430669fc49aa9facb439181081becilix }
42ba1b712b7b430669fc49aa9facb439181081becilix
42ba1b712b7b430669fc49aa9facb439181081becilix return false;
42ba1b712b7b430669fc49aa9facb439181081becilix}
42ba1b712b7b430669fc49aa9facb439181081becilix
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm} /* namespace LivePathEffect */
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm} /* namespace Inkscape */
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm/*
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm Local Variables:
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm mode:c++
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm c-file-style:"stroustrup"
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm indent-tabs-mode:nil
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm fill-column:99
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm End:
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm*/
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :