summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 31846b7)
raw | patch | inline | side by side (parent: 31846b7)
author | jfbarraud <jfbarraud@users.sourceforge.net> | |
Fri, 5 Jun 2009 08:45:30 +0000 (08:45 +0000) | ||
committer | jfbarraud <jfbarraud@users.sourceforge.net> | |
Fri, 5 Jun 2009 08:45:30 +0000 (08:45 +0000) |
src/live_effects/effect.cpp | patch | blob | history | |
src/live_effects/lpe-ruler.cpp | patch | blob | history | |
src/live_effects/lpe-ruler.h | patch | blob | history |
index 088e9ff3a0906f82edadb73b7ee34f0351dda1c4..316495eb4564bd32bae97e69df44bbf9e908d90a 100644 (file)
{PERSPECTIVE_PATH, N_("Perspective path"), "perspective_path"},
{COPY_ROTATE, N_("Rotate copies"), "copy_rotate"},
{RECURSIVE_SKELETON, N_("Recursive skeleton"), "recursive_skeleton"},
- {RULER, N_("Ruler"), "ruler"},
{TANGENT_TO_CURVE, N_("Tangent to curve"), "tangent_to_curve"},
{TEXT_LABEL, N_("Text label"), "text_label"},
#endif
{INTERPOLATE, N_("Interpolate Sub-Paths"), "interpolate"},
{ROUGH_HATCHES, N_("Hatches (rough)"), "rough_hatches"},
{SKETCH, N_("Sketch"), "sketch"},
+ {RULER, N_("Ruler"), "ruler"},
};
const Util::EnumDataConverter<EffectType> LPETypeConverter(LPETypeData, sizeof(LPETypeData)/sizeof(*LPETypeData));
index 1df0e127a0432511cb99a0e34413db512b5a1edc..67bffa1e278c15287bbf0b762f7e8dfe136c0c8e 100644 (file)
LPERuler::LPERuler(LivePathEffectObject *lpeobject) :
Effect(lpeobject),
+ unit(_("Unit"), _("Unit"), "unit", &wr, this),
mark_distance(_("Mark distance"), _("Distance between successive ruler marks"), "mark_distance", &wr, this, 20.0),
mark_length(_("Major length"), _("Length of major ruler marks"), "mark_length", &wr, this, 14.0),
minor_mark_length(_("Minor length"), _("Length of minor ruler marks"), "minor_mark_length", &wr, this, 7.0),
offset(_("Offset"), _("Offset of first mark"), "offset", &wr, this, 0.0),
border_marks(_("Border marks"), _("Choose whether to draw marks at the beginning and end of the path"), "border_marks", BorderMarkTypeConverter, &wr, this, BORDERMARK_BOTH)
{
+ registerParameter(dynamic_cast<Parameter *>(&unit));
registerParameter(dynamic_cast<Parameter *>(&mark_distance));
registerParameter(dynamic_cast<Parameter *>(&mark_length));
registerParameter(dynamic_cast<Parameter *>(&minor_mark_length));
{
using namespace Geom;
- n_major = mark_length * n;
- n_minor = minor_mark_length * n;
+ gboolean success;
+ double real_mark_length = mark_length;
+ success = sp_convert_distance(&real_mark_length, unit, &sp_unit_get_by_id(SP_UNIT_PX));
+ double real_minor_mark_length = minor_mark_length;
+ success = sp_convert_distance(&real_minor_mark_length, unit, &sp_unit_get_by_id(SP_UNIT_PX));
+
+ n_major = real_mark_length * n;
+ n_minor = real_minor_mark_length * n;
Point C, D;
switch (marktype) {
@@ -122,12 +130,17 @@ LPERuler::doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwd2_i
//find at which times to draw a mark:
std::vector<double> s_cuts;
- for (double s = offset; s<totlength; s+=mark_distance){
+
+ double real_mark_distance = mark_distance;
+ gboolean success = sp_convert_distance(&real_mark_distance, unit, &sp_unit_get_by_id(SP_UNIT_PX));
+
+ double real_offset = offset;
+ success = sp_convert_distance(&real_offset, unit, &sp_unit_get_by_id(SP_UNIT_PX));
+ for (double s = real_offset; s<totlength; s+=real_mark_distance){
s_cuts.push_back(s);
}
std::vector<std::vector<double> > roots = multi_roots(arclength, s_cuts);
std::vector<double> t_cuts;
- g_warning("times:");
for (unsigned v=0; v<roots.size();v++){
//FIXME: 2geom multi_roots solver seem to sometimes "repeat" solutions.
//Here, we are supposed to have one and only one solution for each s.
@@ -154,6 +167,17 @@ LPERuler::doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwd2_i
if (border_marks == BORDERMARK_END || border_marks == BORDERMARK_BOTH){
Point A = pwd2_in.lastValue();
Point n = rot90(unit_vector(speed.lastValue()))*sign;
+ //speed.lastValue() is somtimes wrong when the path is closed: a tiny line seg might added at the end to fix rounding errors...
+ //TODO: Find a better fix!! (How do we know if the path was closed?)
+ if ( A == pwd2_in.firstValue() &&
+ speed.segs.size() > 1 &&
+ speed.segs.back()[X].size() <= 1 &&
+ speed.segs.back()[Y].size() <= 1 &&
+ speed.segs.back()[X].tailError(0) <= 1e-10 &&
+ speed.segs.back()[Y].tailError(0) <= 1e-10
+ ){
+ n = rot90(unit_vector(speed.segs[speed.segs.size()-2].at1()))*sign;
+ }
output.concat (ruler_mark(A, n, MARK_MAJOR));
}
index 6a7a7282bbc943d7df6ad926d7a53c5093f6e915..0c72f1637a3824ddf135245951c69f2d1daff5c8 100644 (file)
#include "live_effects/parameter/text.h"
#include "live_effects/parameter/enum.h"
#include "live_effects/parameter/bool.h"
+#include "live_effects/parameter/unit.h"
namespace Inkscape {
namespace LivePathEffect {
Geom::Piecewise<Geom::D2<Geom::SBasis> > ruler_mark(Geom::Point const &A, Geom::Point const &n, MarkType const &marktype);
ScalarParam mark_distance;
+ UnitParam unit;
ScalarParam mark_length;
ScalarParam minor_mark_length;
ScalarParam major_mark_steps;