effect.cpp revision 4afe3fc6b9c122bc5c02b27aea3845ba41384d2a
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 "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>
2e2b8bd323e3693f9d86f545ce049d3f1b45d1c2cilix#include <2geom/pathvector.h>
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"
0a75b58e47d3de42550c4f7960e253ea3befc09ajohanengelen#include "live_effects/lpe-interpolate.h"
4afe3fc6b9c122bc5c02b27aea3845ba41384d2acilix#include "live_effects/lpe-text_label.h"
e54ce05030e6aab675331e18f46f029f55ed1bf0cilix// end of includes
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrmnamespace Inkscape {
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrmnamespace LivePathEffect {
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
72b7b31db250f20b90730d2888e6a554b434a407johanengelenconst Util::EnumData<EffectType> LPETypeData[] = {
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm // {constant defined in effect.h, N_("name of your effect"), "name of your effect in SVG"}
9de5f3bfa8e35ad5e6adcd6eaad4d0d49e7043a3johanengelen {ANGLE_BISECTOR, N_("Angle bisector"), "angle_bisector"},
9de5f3bfa8e35ad5e6adcd6eaad4d0d49e7043a3johanengelen {BEND_PATH, N_("Bend"), "bend_path"},
9de5f3bfa8e35ad5e6adcd6eaad4d0d49e7043a3johanengelen {BOOLOPS, N_("Boolops"), "boolops"},
9de5f3bfa8e35ad5e6adcd6eaad4d0d49e7043a3johanengelen {CIRCLE_WITH_RADIUS, N_("Circle (center+radius)"), "circle_with_radius"},
9de5f3bfa8e35ad5e6adcd6eaad4d0d49e7043a3johanengelen {CIRCLE_3PTS, N_("Circle through 3 points"), "circle_3pts"},
9de5f3bfa8e35ad5e6adcd6eaad4d0d49e7043a3johanengelen {CONSTRUCT_GRID, N_("Construct grid"), "construct_grid"},
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm#ifdef LPE_ENABLE_TEST_EFFECTS
9de5f3bfa8e35ad5e6adcd6eaad4d0d49e7043a3johanengelen {DOEFFECTSTACK_TEST, N_("doEffect stack test"), "doeffectstacktest"},
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm#endif
9de5f3bfa8e35ad5e6adcd6eaad4d0d49e7043a3johanengelen {ENVELOPE, N_("Envelope Deformation"), "envelope"},
9de5f3bfa8e35ad5e6adcd6eaad4d0d49e7043a3johanengelen {FREEHAND_SHAPE, N_("Freehand Shape"), "freehand_shape"}, // this is actually a special type of PatternAlongPath, used to paste shapes in pen/pencil tool
9de5f3bfa8e35ad5e6adcd6eaad4d0d49e7043a3johanengelen {GEARS, N_("Gears"), "gears"},
9de5f3bfa8e35ad5e6adcd6eaad4d0d49e7043a3johanengelen {INTERPOLATE, N_("Interpolate Sub-Paths"), "interpolate"},
9de5f3bfa8e35ad5e6adcd6eaad4d0d49e7043a3johanengelen {KNOT, N_("Knot"), "knot"},
9de5f3bfa8e35ad5e6adcd6eaad4d0d49e7043a3johanengelen {LATTICE, N_("Lattice Deformation"), "lattice"},
9de5f3bfa8e35ad5e6adcd6eaad4d0d49e7043a3johanengelen {MIRROR_SYMMETRY, N_("Mirror symmetry"), "mirror_symmetry"},
9de5f3bfa8e35ad5e6adcd6eaad4d0d49e7043a3johanengelen {OFFSET, N_("Offset"), "offset"},
9de5f3bfa8e35ad5e6adcd6eaad4d0d49e7043a3johanengelen {PARALLEL, N_("Parallel"), "parallel"},
9de5f3bfa8e35ad5e6adcd6eaad4d0d49e7043a3johanengelen {PATTERN_ALONG_PATH, N_("Pattern Along Path"), "skeletal"}, // for historic reasons, this effect is called skeletal(strokes) in Inkscape:SVG
9de5f3bfa8e35ad5e6adcd6eaad4d0d49e7043a3johanengelen {PERP_BISECTOR, N_("Perpendicular bisector"), "perp_bisector"},
9de5f3bfa8e35ad5e6adcd6eaad4d0d49e7043a3johanengelen {PERSPECTIVE_PATH, N_("Perspective path"), "perspective_path"},
9de5f3bfa8e35ad5e6adcd6eaad4d0d49e7043a3johanengelen {COPY_ROTATE, N_("Rotate copies"), "copy_rotate"},
9de5f3bfa8e35ad5e6adcd6eaad4d0d49e7043a3johanengelen {RULER, N_("Ruler"), "ruler"},
9de5f3bfa8e35ad5e6adcd6eaad4d0d49e7043a3johanengelen {SKETCH, N_("Sketch"), "sketch"},
9de5f3bfa8e35ad5e6adcd6eaad4d0d49e7043a3johanengelen {SPIRO, N_("Spiro spline"), "spiro"},
9de5f3bfa8e35ad5e6adcd6eaad4d0d49e7043a3johanengelen {CURVE_STITCH, N_("Stitch Sub-Paths"), "curvestitching"},
9de5f3bfa8e35ad5e6adcd6eaad4d0d49e7043a3johanengelen {TANGENT_TO_CURVE, N_("Tangent to curve"), "tangent_to_curve"},
4afe3fc6b9c122bc5c02b27aea3845ba41384d2acilix {TEXT_LABEL, N_("Text label"), "text_label"},
9de5f3bfa8e35ad5e6adcd6eaad4d0d49e7043a3johanengelen {VONKOCH, N_("VonKoch"), "vonkoch"},
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm};
72b7b31db250f20b90730d2888e6a554b434a407johanengelenconst Util::EnumDataConverter<EffectType> LPETypeConverter(LPETypeData, sizeof(LPETypeData)/sizeof(*LPETypeData));
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;
0a75b58e47d3de42550c4f7960e253ea3befc09ajohanengelen case INTERPOLATE:
0a75b58e47d3de42550c4f7960e253ea3befc09ajohanengelen neweffect = static_cast<Effect*> ( new LPEInterpolate(lpeobj) );
0a75b58e47d3de42550c4f7960e253ea3befc09ajohanengelen break;
4afe3fc6b9c122bc5c02b27aea3845ba41384d2acilix case TEXT_LABEL:
4afe3fc6b9c122bc5c02b27aea3845ba41384d2acilix neweffect = static_cast<Effect*> ( new LPETextLabel(lpeobj) );
4afe3fc6b9c122bc5c02b27aea3845ba41384d2acilix 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{
72b7b31db250f20b90730d2888e6a554b434a407johanengelen if (lpeobj->effecttype_set && LPETypeConverter.is_valid_id(lpeobj->effecttype) )
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) {
797bee69297bbdd86c5cff2e0771a71d1e2ac69dcilix using namespace Inkscape::LivePathEffect;
797bee69297bbdd86c5cff2e0771a71d1e2ac69dcilix
797bee69297bbdd86c5cff2e0771a71d1e2ac69dcilix // add handles provided by the effect itself
25ad3718fb4b96b39930af8e043c8ee1e624fd10cilix addKnotHolderEntities(knotholder, desktop, item);
25ad3718fb4b96b39930af8e043c8ee1e624fd10cilix
25ad3718fb4b96b39930af8e043c8ee1e624fd10cilix // add handles provided by the effect's parameters (if any)
25ad3718fb4b96b39930af8e043c8ee1e624fd10cilix for (std::vector<Parameter *>::iterator p = param_vector.begin(); p != param_vector.end(); ++p) {
25ad3718fb4b96b39930af8e043c8ee1e624fd10cilix (*p)->addKnotHolderEntities(knotholder, desktop, item);
25ad3718fb4b96b39930af8e043c8ee1e624fd10cilix }
25ad3718fb4b96b39930af8e043c8ee1e624fd10cilix}
25ad3718fb4b96b39930af8e043c8ee1e624fd10cilix
25ad3718fb4b96b39930af8e043c8ee1e624fd10cilixvoid
25ad3718fb4b96b39930af8e043c8ee1e624fd10cilixEffect::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item) {
25ad3718fb4b96b39930af8e043c8ee1e624fd10cilix // TODO: The entities in kh_entity_vector are already instantiated during the call
25ad3718fb4b96b39930af8e043c8ee1e624fd10cilix // to registerKnotHolderHandle(), but they are recreated here. Also, we must not
25ad3718fb4b96b39930af8e043c8ee1e624fd10cilix // delete them when the knotholder is destroyed, whence the clumsy function
25ad3718fb4b96b39930af8e043c8ee1e624fd10cilix // isDeletable(). If we could create entities of different classes dynamically,
25ad3718fb4b96b39930af8e043c8ee1e624fd10cilix // this would be much nicer. How to do this?
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
2e2b8bd323e3693f9d86f545ce049d3f1b45d1c2cilix/**
2e2b8bd323e3693f9d86f545ce049d3f1b45d1c2cilix * Return a vector of PathVectors which contain all helperpaths that should be drawn by the effect.
2e2b8bd323e3693f9d86f545ce049d3f1b45d1c2cilix * This is the function called by external code like SPLPEItem.
2e2b8bd323e3693f9d86f545ce049d3f1b45d1c2cilix */
2e2b8bd323e3693f9d86f545ce049d3f1b45d1c2cilixstd::vector<Geom::PathVector>
2e2b8bd323e3693f9d86f545ce049d3f1b45d1c2cilixEffect::getHelperPaths(SPLPEItem *lpeitem)
04c99c338ffdc6e10cb6f5c18f6f06b3f555e8ebcilix{
2e2b8bd323e3693f9d86f545ce049d3f1b45d1c2cilix std::vector<Geom::PathVector> hp_vec;
2e2b8bd323e3693f9d86f545ce049d3f1b45d1c2cilix
2e2b8bd323e3693f9d86f545ce049d3f1b45d1c2cilix if (!SP_IS_SHAPE(lpeitem)) {
2e2b8bd323e3693f9d86f545ce049d3f1b45d1c2cilix g_print ("How to handle helperpaths for non-shapes?\n");
2e2b8bd323e3693f9d86f545ce049d3f1b45d1c2cilix return hp_vec;
04c99c338ffdc6e10cb6f5c18f6f06b3f555e8ebcilix }
bb78cf2c3a2ee8ea2c98433128556847f03f5799cilix
2e2b8bd323e3693f9d86f545ce049d3f1b45d1c2cilix // TODO: we can probably optimize this by using a lot more references
2e2b8bd323e3693f9d86f545ce049d3f1b45d1c2cilix // rather than copying PathVectors all over the place
2e2b8bd323e3693f9d86f545ce049d3f1b45d1c2cilix if (show_orig_path) {
2e2b8bd323e3693f9d86f545ce049d3f1b45d1c2cilix // add original path to helperpaths
2e2b8bd323e3693f9d86f545ce049d3f1b45d1c2cilix SPCurve* curve = sp_shape_get_curve (SP_SHAPE(lpeitem));
2e2b8bd323e3693f9d86f545ce049d3f1b45d1c2cilix hp_vec.push_back(curve->get_pathvector());
2e2b8bd323e3693f9d86f545ce049d3f1b45d1c2cilix }
732fb09f9c502000068a77667c3356cbbd5d39d5cilix
2e2b8bd323e3693f9d86f545ce049d3f1b45d1c2cilix // add other helperpaths provided by the effect itself
2e2b8bd323e3693f9d86f545ce049d3f1b45d1c2cilix addCanvasIndicators(lpeitem, hp_vec);
2e2b8bd323e3693f9d86f545ce049d3f1b45d1c2cilix
2e2b8bd323e3693f9d86f545ce049d3f1b45d1c2cilix // add helperpaths provided by the effect's parameters
2e2b8bd323e3693f9d86f545ce049d3f1b45d1c2cilix for (std::vector<Parameter *>::iterator p = param_vector.begin(); p != param_vector.end(); ++p) {
2e2b8bd323e3693f9d86f545ce049d3f1b45d1c2cilix (*p)->addCanvasIndicators(lpeitem, hp_vec);
732fb09f9c502000068a77667c3356cbbd5d39d5cilix }
732fb09f9c502000068a77667c3356cbbd5d39d5cilix
2e2b8bd323e3693f9d86f545ce049d3f1b45d1c2cilix return hp_vec;
04c99c338ffdc6e10cb6f5c18f6f06b3f555e8ebcilix}
04c99c338ffdc6e10cb6f5c18f6f06b3f555e8ebcilix
2e2b8bd323e3693f9d86f545ce049d3f1b45d1c2cilix/**
2e2b8bd323e3693f9d86f545ce049d3f1b45d1c2cilix * Add possible canvas indicators (i.e., helperpaths other than the original path) to \a hp_vec
2e2b8bd323e3693f9d86f545ce049d3f1b45d1c2cilix * This function should be overwritten by derived effects if they want to provide their own helperpaths.
2e2b8bd323e3693f9d86f545ce049d3f1b45d1c2cilix */
04c99c338ffdc6e10cb6f5c18f6f06b3f555e8ebcilixvoid
2e2b8bd323e3693f9d86f545ce049d3f1b45d1c2cilixEffect::addCanvasIndicators(SPLPEItem *lpeitem, std::vector<Geom::PathVector> &hp_vec)
04c99c338ffdc6e10cb6f5c18f6f06b3f555e8ebcilix{
04c99c338ffdc6e10cb6f5c18f6f06b3f555e8ebcilix}
04c99c338ffdc6e10cb6f5c18f6f06b3f555e8ebcilix
2e2b8bd323e3693f9d86f545ce049d3f1b45d1c2cilix
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
797bee69297bbdd86c5cff2e0771a71d1e2ac69dcilix// TODO: take _all_ parameters into account, not only PointParams
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) {
2e2b8bd323e3693f9d86f545ce049d3f1b45d1c2cilix// if ( Inkscape::LivePathEffect::PointParam *pointparam = dynamic_cast<Inkscape::LivePathEffect::PointParam*>(*p) ) {
2e2b8bd323e3693f9d86f545ce049d3f1b45d1c2cilix if (dynamic_cast<Inkscape::LivePathEffect::PointParam*>(*p)) {
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 :