1 /** @file
2 * @brief LPE knot effect implementation
3 */
4 /* Authors:
5 * Jean-Francois Barraud <jf.barraud@gmail.com>
6 *
7 * Copyright (C) 2007 Authors
8 *
9 * Released under GNU GPL, read the file 'COPYING' for more information
10 */
12 #include "sp-shape.h"
13 #include "sp-path.h"
14 #include "display/curve.h"
15 #include "live_effects/lpe-knot.h"
16 #include "svg/svg.h"
17 #include "style.h"
18 #include "knot-holder-entity.h"
20 #include <2geom/sbasis-to-bezier.h>
21 #include <2geom/sbasis.h>
22 #include <2geom/d2.h>
23 #include <2geom/d2-sbasis.h>
24 #include <2geom/path.h>
25 //#include <2geom/crossing.h>
26 #include <2geom/bezier-to-sbasis.h>
27 #include <2geom/basic-intersection.h>
28 #include <2geom/exception.h>
30 // for change crossing undo
31 #include "verbs.h"
32 #include "document.h"
34 #include <exception>
36 namespace Inkscape {
37 namespace LivePathEffect {
39 class KnotHolderEntityCrossingSwitcher : public LPEKnotHolderEntity
40 {
41 public:
42 virtual ~KnotHolderEntityCrossingSwitcher() {}
44 virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state);
45 virtual Geom::Point knot_get();
46 virtual void knot_click(guint state);
47 };
50 //---------------------------------------------------------------------------
51 //LPEKnot specific Interval manipulation.
52 //---------------------------------------------------------------------------
54 //remove an interval from an union of intervals.
55 //TODO: is it worth moving it to 2Geom?
56 static
57 std::vector<Geom::Interval> complementOf(Geom::Interval I, std::vector<Geom::Interval> domain){
58 std::vector<Geom::Interval> ret;
59 if (!domain.empty()) {
60 double min = domain.front().min();
61 double max = domain.back().max();
62 Geom::Interval I1 = Geom::Interval(min,I.min());
63 Geom::Interval I2 = Geom::Interval(I.max(),max);
65 for (unsigned i = 0; i<domain.size(); i++){
66 boost::optional<Geom::Interval> I1i = intersect(domain.at(i),I1);
67 if (I1i && !I1i->isSingular()) ret.push_back(I1i.get());
68 boost::optional<Geom::Interval> I2i = intersect(domain.at(i),I2);
69 if (I2i && !I2i->isSingular()) ret.push_back(I2i.get());
70 }
71 }
72 return ret;
73 }
75 //find the time interval during which patha is hidden by pathb near a given crossing.
76 // Warning: not accurate!
77 static
78 Geom::Interval
79 findShadowedTime(Geom::Path const &patha, std::vector<Geom::Point> const &pt_and_dir,
80 double const ta, double const width){
81 using namespace Geom;
82 Point T = unit_vector(pt_and_dir[1]);
83 Point N = T.cw();
84 Point A = pt_and_dir[0]-3*width*T, B = A+6*width*T;
86 Matrix mat = from_basis( T, N, pt_and_dir[0] );
87 mat = mat.inverse();
88 Path p = patha * mat;
90 std::vector<double> times;
92 //TODO: explore the path fwd/backward from ta (worth?)
93 for (unsigned i=0; i<patha.size(); i++){
94 D2<SBasis> f = p[i].toSBasis();
95 std::vector<double> times_i, temptimes;
96 temptimes = roots(f[Y]-width);
97 times_i.insert(times_i.end(), temptimes.begin(), temptimes.end() );
98 temptimes = roots(f[Y]+width);
99 times_i.insert(times_i.end(), temptimes.begin(), temptimes.end() );
100 temptimes = roots(f[X]-3*width);
101 times_i.insert(times_i.end(), temptimes.begin(), temptimes.end() );
102 temptimes = roots(f[X]+3*width);
103 times_i.insert(times_i.end(), temptimes.begin(), temptimes.end() );
104 for (unsigned k=0; k<times_i.size(); k++){
105 times_i[k]+=i;
106 }
107 times.insert(times.end(), times_i.begin(), times_i.end() );
108 }
109 std::sort( times.begin(), times.end() );
110 std::vector<double>::iterator new_end = std::unique( times.begin(), times.end() );
111 times.resize( new_end - times.begin() );
113 double tmin = 0, tmax = patha.size();
114 double period = patha.size();//hm... Should this be patha.size()+1?
115 if (times.size()>0){
116 unsigned rk = upper_bound( times.begin(), times.end(), ta ) - times.begin();
117 if ( rk < times.size() )
118 tmax = times[rk];
119 else if ( patha.closed() )
120 tmax = times[0]+period;
122 if ( rk > 0 )
123 tmin = times[rk-1];
124 else if ( patha.closed() )
125 tmin = times.back()-period;
126 }
127 return Interval(tmin,tmax);
128 }
130 //---------------------------------------------------------------------------
131 //LPEKnot specific Crossing Data manipulation.
132 //---------------------------------------------------------------------------
134 //Yet another crossing data representation.
135 // an CrossingPoint stores
136 // -an intersection point
137 // -the involved path components
138 // -for each component, the time at which this crossing occurs + the order of this crossing along the component (when starting from 0).
140 namespace LPEKnotNS {//just in case...
141 CrossingPoints::CrossingPoints(std::vector<Geom::Path> const &paths) : std::vector<CrossingPoint>(){
142 // std::cout<<"\nCrossingPoints creation from path vector\n";
143 for( unsigned i=0; i<paths.size(); i++){
144 for( unsigned ii=0; ii<paths[i].size(); ii++){
145 for( unsigned j=i; j<paths.size(); j++){
146 for( unsigned jj=(i==j?ii:0); jj<paths[j].size(); jj++){
147 std::vector<std::pair<double,double> > times;
148 if ( i==j && ii==jj){
150 // std::cout<<"--(self int)\n";
151 // std::cout << paths[i][ii].toSBasis()[Geom::X] <<"\n";
152 // std::cout << paths[i][ii].toSBasis()[Geom::Y] <<"\n";
154 find_self_intersections( times, paths[i][ii].toSBasis() );
155 }else{
156 // std::cout<<"--(pair int)\n";
157 // std::cout << paths[i][ii].toSBasis()[Geom::X] <<"\n";
158 // std::cout << paths[i][ii].toSBasis()[Geom::Y] <<"\n";
159 // std::cout<<"with\n";
160 // std::cout << paths[j][jj].toSBasis()[Geom::X] <<"\n";
161 // std::cout << paths[j][jj].toSBasis()[Geom::Y] <<"\n";
163 find_intersections( times, paths[i][ii].toSBasis(), paths[j][jj].toSBasis() );
164 }
165 for (unsigned k=0; k<times.size(); k++){
166 //std::cout<<"intersection "<<i<<"["<<ii<<"]("<<times[k].first<<")= "<<j<<"["<<jj<<"]("<<times[k].second<<")\n";
167 if (times[k].first == times[k].first && times[k].second == times[k].second ){//is this the way to test NaN?
168 double zero = 1e-4;
169 if ( i==j && fabs(times[k].first+ii - times[k].second-jj)<=zero ){//this is just end=start of successive curves in a path.
170 continue;
171 }
172 if ( i==j && ii == 0 && jj==paths[i].size()-1 &&
173 paths[i].closed() &&
174 fabs(times[k].first) <= zero &&
175 fabs(times[k].second - 1) <= zero ){//this is just end=start of a closed path.
176 continue;
177 }
178 CrossingPoint cp;
179 cp.pt = paths[i][ii].pointAt(times[k].first);
180 cp.sign = 1;
181 cp.i = i;
182 cp.j = j;
183 cp.ni = 0; cp.nj=0;//not set yet
184 cp.ti = times[k].first + ii;
185 cp.tj = times[k].second + jj;
186 push_back(cp);
187 }else{
188 std::cout<<"ooops: find_(self)_intersections returned NaN:";
189 //std::cout<<"intersection "<<i<<"["<<ii<<"](NaN)= "<<j<<"["<<jj<<"](NaN)\n";
190 }
191 }
192 }
193 }
194 }
195 }
196 for( unsigned i=0; i<paths.size(); i++){
197 std::map < double, unsigned > cuts;
198 for( unsigned k=0; k<size(); k++){
199 CrossingPoint cp = (*this)[k];
200 if (cp.i == i) cuts[cp.ti] = k;
201 if (cp.j == i) cuts[cp.tj] = k;
202 }
203 unsigned count = 0;
204 for ( std::map < double, unsigned >::iterator m=cuts.begin(); m!=cuts.end(); m++ ){
205 if ( (*this)[m->second].i == i && (*this)[m->second].ti == m->first ){
206 (*this)[m->second].ni = count;
207 }else{
208 (*this)[m->second].nj = count;
209 }
210 count++;
211 }
212 }
213 }
215 CrossingPoints::CrossingPoints(std::vector<double> const &input) : std::vector<CrossingPoint>()
216 {
217 if (input.size()>0 && input.size()%9 ==0){
218 using namespace Geom;
219 for( unsigned n=0; n<input.size(); ){
220 CrossingPoint cp;
221 cp.pt[X] = input[n++];
222 cp.pt[Y] = input[n++];
223 cp.i = input[n++];
224 cp.j = input[n++];
225 cp.ni = input[n++];
226 cp.nj = input[n++];
227 cp.ti = input[n++];
228 cp.tj = input[n++];
229 cp.sign = input[n++];
230 push_back(cp);
231 }
232 }
233 }
235 std::vector<double>
236 CrossingPoints::to_vector()
237 {
238 using namespace Geom;
239 std::vector<double> result;
240 for( unsigned n=0; n<size(); n++){
241 CrossingPoint cp = (*this)[n];
242 result.push_back(cp.pt[X]);
243 result.push_back(cp.pt[Y]);
244 result.push_back(double(cp.i));
245 result.push_back(double(cp.j));
246 result.push_back(double(cp.ni));
247 result.push_back(double(cp.nj));
248 result.push_back(double(cp.ti));
249 result.push_back(double(cp.tj));
250 result.push_back(double(cp.sign));
251 }
252 return result;
253 }
255 //FIXME: rewrite to check success: return bool, put result in arg.
256 CrossingPoint
257 CrossingPoints::get(unsigned const i, unsigned const ni)
258 {
259 for (unsigned k=0; k<size(); k++){
260 if (
261 ((*this)[k].i==i && (*this)[k].ni==ni) ||
262 ((*this)[k].j==i && (*this)[k].nj==ni)
263 ) return (*this)[k];
264 }
265 g_warning("LPEKnotNS::CrossingPoints::get error. %uth crossing along string %u not found.",ni,i);
266 assert(false);//debug purpose...
267 return CrossingPoint();
268 }
270 unsigned
271 idx_of_nearest(CrossingPoints const &cpts, Geom::Point const &p)
272 {
273 double dist=-1;
274 unsigned result = cpts.size();
275 for (unsigned k=0; k<cpts.size(); k++){
276 double dist_k = Geom::L2(p-cpts[k].pt);
277 if (dist<0 || dist>dist_k){
278 result = k;
279 dist = dist_k;
280 }
281 }
282 return result;
283 }
285 //TODO: Find a way to warn the user when the topology changes.
286 //TODO: be smarter at guessing the signs when the topology changed?
287 void
288 CrossingPoints::inherit_signs(CrossingPoints const &other, int default_value)
289 {
290 bool topo_changed = false;
291 for (unsigned n=0; n<size(); n++){
292 if ( n<other.size() &&
293 other[n].i == (*this)[n].i &&
294 other[n].j == (*this)[n].j &&
295 other[n].ni == (*this)[n].ni &&
296 other[n].nj == (*this)[n].nj )
297 {
298 (*this)[n].sign = other[n].sign;
299 }else{
300 topo_changed = true;
301 break;
302 }
303 }
304 if (topo_changed){
305 //TODO: Find a way to warn the user!!
306 // std::cout<<"knot topolgy changed!\n";
307 for (unsigned n=0; n<size(); n++){
308 Geom::Point p = (*this)[n].pt;
309 unsigned idx = idx_of_nearest(other,p);
310 if (idx<other.size()){
311 (*this)[n].sign = other[idx].sign;
312 }else{
313 (*this)[n].sign = default_value;
314 }
315 }
316 }
317 }
319 }
321 //---------------------------------------------------------------------------
322 //---------------------------------------------------------------------------
323 //LPEKnot effect.
324 //---------------------------------------------------------------------------
325 //---------------------------------------------------------------------------
328 LPEKnot::LPEKnot(LivePathEffectObject *lpeobject) :
329 Effect(lpeobject),
330 // initialise your parameters here:
331 interruption_width(_("Fixed width"), _("Size of hidden region of lower string"), "interruption_width", &wr, this, 3),
332 prop_to_stroke_width(_("In units of stroke width"), _("Consider 'Interruption width' as a ratio of stroke width"), "prop_to_stroke_width", &wr, this, true),
333 add_stroke_width(_("Stroke width"), _("Add the stroke width to the interruption size"), "add_stroke_width", &wr, this, true),
334 add_other_stroke_width(_("Crossing path stroke width"), _("Add crossed stroke width to the interruption size"), "add_other_stroke_width", &wr, this, true),
335 switcher_size(_("Switcher size"), _("Orientation indicator/switcher size"), "switcher_size", &wr, this, 15),
336 crossing_points_vector(_("Crossing Signs"), _("Crossings signs"), "crossing_points_vector", &wr, this),
337 gpaths(),gstroke_widths()
338 {
339 // register all your parameters here, so Inkscape knows which parameters this effect has:
340 registerParameter( dynamic_cast<Parameter *>(&interruption_width) );
341 registerParameter( dynamic_cast<Parameter *>(&prop_to_stroke_width) );
342 registerParameter( dynamic_cast<Parameter *>(&add_stroke_width) );
343 registerParameter( dynamic_cast<Parameter *>(&add_other_stroke_width) );
344 registerParameter( dynamic_cast<Parameter *>(&switcher_size) );
345 registerParameter( dynamic_cast<Parameter *>(&crossing_points_vector) );
347 registerKnotHolderHandle(new KnotHolderEntityCrossingSwitcher(), _("Drag to select a crossing, click to flip it"));
348 crossing_points = LPEKnotNS::CrossingPoints();
349 selectedCrossing = 0;
350 switcher = Geom::Point(0,0);
351 }
353 LPEKnot::~LPEKnot()
354 {
356 }
358 void
359 LPEKnot::updateSwitcher(){
360 if (selectedCrossing < crossing_points.size()){
361 switcher = crossing_points[selectedCrossing].pt;
362 //std::cout<<"placing switcher at "<<switcher<<" \n";
363 }else if (crossing_points.size()>0){
364 selectedCrossing = 0;
365 switcher = crossing_points[selectedCrossing].pt;
366 //std::cout<<"placing switcher at "<<switcher<<" \n";
367 }else{
368 //std::cout<<"hiding switcher!\n";
369 //TODO: is there a way to properly hide the helper.
370 //switcher = Geom::Point(Geom::infinity(),Geom::infinity());
371 switcher = Geom::Point(1e10,1e10);
372 }
373 }
375 std::vector<Geom::Path>
376 LPEKnot::doEffect_path (std::vector<Geom::Path> const &path_in)
377 {
378 using namespace Geom;
379 std::vector<Geom::Path> path_out;
381 if (gpaths.size()==0){
382 return path_in;
383 }
385 for (unsigned comp=0; comp<path_in.size(); comp++){
387 //find the relevant path component in gpaths (required to allow groups!)
388 //Q: do we always recieve the group members in the same order? can we rest on that?
389 unsigned i0 = 0;
390 for (i0=0; i0<gpaths.size(); i0++){
391 if (path_in[comp]==gpaths[i0]) break;
392 }
393 if (i0 == gpaths.size() ) {THROW_EXCEPTION("lpe-knot error: group member not recognized");}// this should not happen...
395 std::vector<Interval> dom;
396 dom.push_back(Interval(0.,gpaths[i0].size()));
397 for (unsigned p = 0; p < crossing_points.size(); p++){
398 if (crossing_points[p].i == i0 || crossing_points[p].j == i0){
399 unsigned i = crossing_points[p].i;
400 unsigned j = crossing_points[p].j;
401 double ti = crossing_points[p].ti;
402 double tj = crossing_points[p].tj;
404 double curveidx, t;
406 t = modf(ti, &curveidx);
407 if(curveidx == gpaths[i].size() ) { curveidx--; t = 1.;}
408 assert(curveidx >= 0 && curveidx < gpaths[i].size());
409 std::vector<Point> flag_i = gpaths[i][curveidx].pointAndDerivatives(t,1);
411 t = modf(tj, &curveidx);
412 if(curveidx == gpaths[j].size() ) { curveidx--; t = 1.;}
413 assert(curveidx >= 0 && curveidx < gpaths[j].size());
414 std::vector<Point> flag_j = gpaths[j][curveidx].pointAndDerivatives(t,1);
417 int geom_sign = ( cross(flag_i[1],flag_j[1]) > 0 ? 1 : -1);
419 bool i0_is_under = false;
420 if ( crossing_points[p].sign * geom_sign > 0 ){
421 i0_is_under = ( i == i0 );
422 }else if ( crossing_points[p].sign * geom_sign < 0 ){
423 if (j == i0){
424 std::swap( i, j);
425 std::swap(ti, tj);
426 std::swap(flag_i,flag_j);
427 i0_is_under = true;
428 }
429 }
430 if (i0_is_under){
431 double width = interruption_width;
432 if ( prop_to_stroke_width.get_value() ) {
433 width *= gstroke_widths[i];
434 }
435 if ( add_stroke_width.get_value() ) {
436 width += gstroke_widths[i];
437 }
438 if ( add_other_stroke_width.get_value() ) {
439 width += gstroke_widths[j];
440 }
441 Interval hidden = findShadowedTime(gpaths[i0], flag_j, ti, width/2);
442 double period = gpaths[i0].size();//hm... Should this be gpaths[i0].size()+1?
443 if (hidden.max() > period ) hidden -= period;
444 if (hidden.min()<0){
445 dom = complementOf( Interval(0,hidden.max()) ,dom);
446 dom = complementOf( Interval(hidden.min()+period, period) ,dom);
447 }else{
448 dom = complementOf(hidden,dom);
449 }
450 }
451 }
452 }
454 //If the all component is hidden, continue.
455 if ( dom.size() == 0){
456 continue;
457 }
459 //If the current path is closed and the last/first point is still there, glue first and last piece.
460 unsigned beg_comp = 0, end_comp = dom.size();
461 if ( gpaths[i0].closed() && dom.front().min() == 0 && dom.back().max() == gpaths[i0].size() ){
462 if ( dom.size() == 1){
463 path_out.push_back(gpaths[i0]);
464 continue;
465 }else{
466 // std::cout<<"fusing first and last component\n";
467 beg_comp++;
468 end_comp--;
469 Path first = gpaths[i0].portion(dom.back());
470 //FIXME: STITCH_DISCONTINUOUS should not be necessary (?!?)
471 first.append(gpaths[i0].portion(dom.front()), Path::STITCH_DISCONTINUOUS);
472 path_out.push_back(first);
473 }
474 }
475 for (unsigned comp = beg_comp; comp < end_comp; comp++){
476 assert(dom.at(comp).min() >=0 and dom.at(comp).max() <= gpaths.at(i0).size());
477 path_out.push_back(gpaths[i0].portion(dom.at(comp)));
478 }
479 }
480 return path_out;
481 }
485 //recursively collect gpaths and stroke widths (stolen from "sp-lpe_item.cpp").
486 void collectPathsAndWidths (SPLPEItem const *lpeitem, std::vector<Geom::Path> &paths, std::vector<double> &stroke_widths){
487 if (SP_IS_GROUP(lpeitem)) {
488 GSList const *item_list = sp_item_group_item_list(SP_GROUP(lpeitem));
489 for ( GSList const *iter = item_list; iter; iter = iter->next ) {
490 SPObject *subitem = static_cast<SPObject *>(iter->data);
491 if (SP_IS_LPE_ITEM(subitem)) {
492 collectPathsAndWidths(SP_LPE_ITEM(subitem), paths, stroke_widths);
493 }
494 }
495 }
496 else if (SP_IS_SHAPE(lpeitem)) {
497 SPCurve * c = NULL;
498 if (SP_IS_PATH(lpeitem)) {
499 c = sp_path_get_curve_for_edit(SP_PATH(lpeitem));
500 } else {
501 c = sp_shape_get_curve(SP_SHAPE(lpeitem));
502 }
503 if (c) {
504 Geom::PathVector subpaths = c->get_pathvector();
505 for (unsigned i=0; i<subpaths.size(); i++){
506 paths.push_back(subpaths[i]);
507 //FIXME: do we have to be more carefull when trying to access stroke width?
508 stroke_widths.push_back(SP_ITEM(lpeitem)->style->stroke_width.computed);
509 }
510 }
511 }
512 }
515 void
516 LPEKnot::doBeforeEffect (SPLPEItem *lpeitem)
517 {
518 using namespace Geom;
519 original_bbox(lpeitem);
521 gpaths = std::vector<Geom::Path>();
522 gstroke_widths = std::vector<double>();
523 collectPathsAndWidths(lpeitem, gpaths, gstroke_widths);
525 // std::cout<<"\nPaths on input:\n";
526 // for (unsigned i=0; i<gpaths.size(); i++){
527 // for (unsigned ii=0; ii<gpaths[i].size(); ii++){
528 // std::cout << gpaths[i][ii].toSBasis()[Geom::X] <<"\n";
529 // std::cout << gpaths[i][ii].toSBasis()[Geom::Y] <<"\n";
530 // std::cout<<"--\n";
531 // }
532 // }
534 //std::cout<<"crossing_pts_vect: "<<crossing_points_vector.param_getSVGValue()<<".\n";
535 //std::cout<<"prop_to_stroke_width: "<<prop_to_stroke_width.param_getSVGValue()<<".\n";
537 LPEKnotNS::CrossingPoints old_crdata(crossing_points_vector.data());
539 // std::cout<<"\nVectorParam size:"<<crossing_points_vector.data().size()<<"\n";
541 // std::cout<<"\nOld crdata ("<<old_crdata.size()<<"): \n";
542 // for (unsigned toto=0; toto<old_crdata.size(); toto++){
543 // std::cout<<"(";
544 // std::cout<<old_crdata[toto].i<<",";
545 // std::cout<<old_crdata[toto].j<<",";
546 // std::cout<<old_crdata[toto].ni<<",";
547 // std::cout<<old_crdata[toto].nj<<",";
548 // std::cout<<old_crdata[toto].ti<<",";
549 // std::cout<<old_crdata[toto].tj<<",";
550 // std::cout<<old_crdata[toto].sign<<"),";
551 // }
553 //if ( old_crdata.size() > 0 ) std::cout<<"first crossing sign = "<<old_crdata[0].sign<<".\n";
554 //else std::cout<<"old data is empty!!\n";
555 crossing_points = LPEKnotNS::CrossingPoints(gpaths);
556 // std::cout<<"\nNew crdata ("<<crossing_points.size()<<"): \n";
557 // for (unsigned toto=0; toto<crossing_points.size(); toto++){
558 // std::cout<<"(";
559 // std::cout<<crossing_points[toto].i<<",";
560 // std::cout<<crossing_points[toto].j<<",";
561 // std::cout<<crossing_points[toto].ni<<",";
562 // std::cout<<crossing_points[toto].nj<<",";
563 // std::cout<<crossing_points[toto].ti<<",";
564 // std::cout<<crossing_points[toto].tj<<",";
565 // std::cout<<crossing_points[toto].sign<<"),";
566 // }
567 crossing_points.inherit_signs(old_crdata);
568 crossing_points_vector.param_set_and_write_new_value(crossing_points.to_vector());
569 updateSwitcher();
570 }
573 static LPEKnot *
574 get_effect(SPItem *item)
575 {
576 Effect *effect = sp_lpe_item_get_current_lpe(SP_LPE_ITEM(item));
577 if (effect->effectType() != KNOT) {
578 g_print ("Warning: Effect is not of type LPEKnot!\n");
579 return NULL;
580 }
581 return static_cast<LPEKnot *>(effect);
582 }
584 void
585 LPEKnot::addCanvasIndicators(SPLPEItem */*lpeitem*/, std::vector<Geom::PathVector> &hp_vec)
586 {
587 using namespace Geom;
588 double r = switcher_size*.1;
589 char const * svgd;
590 //TODO: use a nice path!
591 if (selectedCrossing >= crossing_points.size()||crossing_points[selectedCrossing].sign > 0){
592 //svgd = "M -10,0 A 10 10 0 1 0 0,-10 l 5,-1 -1,2";
593 svgd = "m -7.07,7.07 c 3.9,3.91 10.24,3.91 14.14,0 3.91,-3.9 3.91,-10.24 0,-14.14 -3.9,-3.91 -10.24,-3.91 -14.14,0 l 2.83,-4.24 0.7,2.12";
594 }else if (crossing_points[selectedCrossing].sign < 0){
595 //svgd = "M 10,0 A 10 10 0 1 1 0,-10 l -5,-1 1,2";
596 svgd = "m 7.07,7.07 c -3.9,3.91 -10.24,3.91 -14.14,0 -3.91,-3.9 -3.91,-10.24 0,-14.14 3.9,-3.91 10.24,-3.91 14.14,0 l -2.83,-4.24 -0.7,2.12";
597 }else{
598 //svgd = "M 10,0 A 10 10 0 1 0 -10,0 A 10 10 0 1 0 10,0 ";
599 svgd = "M 10,0 C 10,5.52 5.52,10 0,10 -5.52,10 -10,5.52 -10,0 c 0,-5.52 4.48,-10 10,-10 5.52,0 10,4.48 10,10 z";
600 }
601 PathVector pathv = sp_svg_read_pathv(svgd);
602 pathv *= Matrix(r,0,0,r,0,0);
603 pathv+=switcher;
604 hp_vec.push_back(pathv);
605 }
607 void
608 KnotHolderEntityCrossingSwitcher::knot_set(Geom::Point const &p, Geom::Point const &/*origin*/, guint /*state*/)
609 {
610 LPEKnot* lpe = get_effect(item);
612 lpe->selectedCrossing = idx_of_nearest(lpe->crossing_points,p);
613 lpe->updateSwitcher();
614 // FIXME: this should not directly ask for updating the item. It should write to SVG, which triggers updating.
615 sp_lpe_item_update_patheffect (SP_LPE_ITEM(item), false, true);
616 }
618 Geom::Point
619 KnotHolderEntityCrossingSwitcher::knot_get()
620 {
621 LPEKnot* lpe = get_effect(item);
622 return snap_knot_position(lpe->switcher);
623 }
625 void
626 KnotHolderEntityCrossingSwitcher::knot_click(guint state)
627 {
628 LPEKnot* lpe = get_effect(item);
629 unsigned s = lpe->selectedCrossing;
630 if (s < lpe->crossing_points.size()){
631 if (state & GDK_SHIFT_MASK){
632 lpe->crossing_points[s].sign = 1;
633 }else{
634 int sign = lpe->crossing_points[s].sign;
635 lpe->crossing_points[s].sign = ((sign+2)%3)-1;
636 //std::cout<<"crossing set to"<<lpe->crossing_points[s].sign<<".\n";
637 }
638 lpe->crossing_points_vector.param_set_and_write_new_value(lpe->crossing_points.to_vector());
639 sp_document_done(lpe->getSPDoc(), SP_VERB_DIALOG_LIVE_PATH_EFFECT, /// @todo Is this the right verb?
640 _("Change knot crossing"));
642 // FIXME: this should not directly ask for updating the item. It should write to SVG, which triggers updating.
643 // sp_lpe_item_update_patheffect (SP_LPE_ITEM(item), false, true);
644 }
645 }
648 /* ######################## */
650 } // namespace LivePathEffect
651 } // namespace Inkscape
653 /*
654 Local Variables:
655 mode:c++
656 c-file-style:"stroustrup"
657 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
658 indent-tabs-mode:nil
659 fill-column:99
660 End:
661 */
662 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :