Code

Connector tool: make connectors avoid the convex hull of shapes.
[inkscape.git] / src / live_effects / lpe-knot.cpp
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     double min = domain.front().min();
60     double max = domain.back().max();
61     Geom::Interval I1 = Geom::Interval(min,I.min());
62     Geom::Interval I2 = Geom::Interval(I.max(),max);
64     for (unsigned i = 0; i<domain.size(); i++){
65         boost::optional<Geom::Interval> I1i = intersect(domain.at(i),I1);
66         if (I1i && !I1i->isSingular()) ret.push_back(I1i.get());
67         boost::optional<Geom::Interval> I2i = intersect(domain.at(i),I2);
68         if (I2i && !I2i->isSingular()) ret.push_back(I2i.get());
69     }    
70     return ret;
71 }
73 //find the time interval during which patha is hidden by pathb near a given crossing.
74 // Warning: not accurate!
75 static
76 Geom::Interval
77 findShadowedTime(Geom::Path const &patha, std::vector<Geom::Point> const &pt_and_dir,
78                  double const ta, double const width){
79     using namespace Geom;
80     Point T = unit_vector(pt_and_dir[1]);
81     Point N = T.cw();
82     Point A = pt_and_dir[0]-3*width*T, B = A+6*width*T;
84     Matrix mat = from_basis( T, N, pt_and_dir[0] );
85     mat = mat.inverse();
86     Path p = patha * mat;
87     
88     std::vector<double> times;
89     
90     //TODO: explore the path fwd/backward from ta (worth?)
91     for (unsigned i=0; i<patha.size(); i++){
92         D2<SBasis> f = p[i].toSBasis();
93         std::vector<double> times_i, temptimes;
94         temptimes = roots(f[Y]-width);
95         times_i.insert(times_i.end(), temptimes.begin(), temptimes.end() ); 
96         temptimes = roots(f[Y]+width);
97         times_i.insert(times_i.end(), temptimes.begin(), temptimes.end() ); 
98         temptimes = roots(f[X]-3*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         for (unsigned k=0; k<times_i.size(); k++){
103             times_i[k]+=i;
104         }
105         times.insert(times.end(), times_i.begin(), times_i.end() );
106     }
107     std::sort( times.begin(),  times.end() );
108     std::vector<double>::iterator new_end = std::unique( times.begin(),  times.end() );
109     times.resize( new_end - times.begin() );
111     double tmin = 0, tmax = patha.size();
112     double period = patha.size();//hm... Should this be patha.size()+1? 
113     if (times.size()>0){
114         unsigned rk = upper_bound( times.begin(),  times.end(), ta ) - times.begin();
115         if ( rk < times.size() ) 
116             tmax = times[rk];
117         else if ( patha.closed() ) 
118             tmax = times[0]+period;
120         if ( rk > 0 ) 
121             tmin = times[rk-1];
122         else if ( patha.closed() ) 
123             tmin = times.back()-period;
124     }
125     return Interval(tmin,tmax);
128 //---------------------------------------------------------------------------
129 //LPEKnot specific Crossing Data manipulation.
130 //---------------------------------------------------------------------------
132 //Yet another crossing data representation.
133 // an CrossingPoint stores
134 //    -an intersection point
135 //    -the involved path components
136 //    -for each component, the time at which this crossing occurs + the order of this crossing along the component (when starting from 0).
138 namespace LPEKnotNS {//just in case...
139 CrossingPoints::CrossingPoints(std::vector<Geom::Path> const &paths) : std::vector<CrossingPoint>(){
140 //    std::cout<<"\nCrossingPoints creation from path vector\n";
141     for( unsigned i=0; i<paths.size(); i++){
142         for( unsigned ii=0; ii<paths[i].size(); ii++){
143             for( unsigned j=i; j<paths.size(); j++){
144                 for( unsigned jj=(i==j?ii:0); jj<paths[j].size(); jj++){
145                     std::vector<std::pair<double,double> > times;
146                     if ( i==j && ii==jj){
148 //                         std::cout<<"--(self int)\n";
149 //                         std::cout << paths[i][ii].toSBasis()[Geom::X] <<"\n";
150 //                         std::cout << paths[i][ii].toSBasis()[Geom::Y] <<"\n";
152                         find_self_intersections( times, paths[i][ii].toSBasis() );
153                     }else{
154 //                         std::cout<<"--(pair int)\n";
155 //                         std::cout << paths[i][ii].toSBasis()[Geom::X] <<"\n";
156 //                         std::cout << paths[i][ii].toSBasis()[Geom::Y] <<"\n";
157 //                         std::cout<<"with\n";
158 //                         std::cout << paths[j][jj].toSBasis()[Geom::X] <<"\n";
159 //                         std::cout << paths[j][jj].toSBasis()[Geom::Y] <<"\n";
161                         find_intersections( times, paths[i][ii].toSBasis(), paths[j][jj].toSBasis() );
162                     }
163                     for (unsigned k=0; k<times.size(); k++){
164                         //std::cout<<"intersection "<<i<<"["<<ii<<"]("<<times[k].first<<")= "<<j<<"["<<jj<<"]("<<times[k].second<<")\n";
165                         if (times[k].first == times[k].first && times[k].second == times[k].second ){//is this the way to test NaN?
166                             double zero = 1e-4;
167                             if ( i==j && fabs(times[k].first+ii - times[k].second-jj)<=zero ){//this is just end=start of successive curves in a path.
168                                 continue;
169                             }
170                             if ( i==j && ii == 0 && jj==paths[i].size()-1 &&
171                                  paths[i].closed() &&
172                                  fabs(times[k].first) <= zero && 
173                                  fabs(times[k].second - 1) <= zero ){//this is just end=start of a closed path.
174                                 continue;
175                             }
176                             CrossingPoint cp;
177                             cp.pt = paths[i][ii].pointAt(times[k].first);
178                             cp.sign = 1;
179                             cp.i = i;
180                             cp.j = j;
181                             cp.ni = 0; cp.nj=0;//not set yet
182                             cp.ti = times[k].first + ii;
183                             cp.tj = times[k].second + jj;
184                             push_back(cp);
185                         }else{
186                             std::cout<<"ooops: find_(self)_intersections returned NaN:";
187                             //std::cout<<"intersection "<<i<<"["<<ii<<"](NaN)= "<<j<<"["<<jj<<"](NaN)\n";
188                         }
189                     }
190                 }
191             }
192         }
193     }
194     for( unsigned i=0; i<paths.size(); i++){
195         std::map < double, unsigned > cuts;
196         for( unsigned k=0; k<size(); k++){
197             CrossingPoint cp = (*this)[k];
198             if (cp.i == i) cuts[cp.ti] = k;
199             if (cp.j == i) cuts[cp.tj] = k;
200         }
201         unsigned count = 0;
202         for ( std::map < double, unsigned >::iterator m=cuts.begin(); m!=cuts.end(); m++ ){
203             if ( (*this)[m->second].i == i && (*this)[m->second].ti == m->first ){
204                 (*this)[m->second].ni = count;
205             }else{
206                 (*this)[m->second].nj = count;
207             }
208             count++;
209         }
210     }
213 CrossingPoints::CrossingPoints(std::vector<double> const &input) : std::vector<CrossingPoint>()
215     if (input.size()>0 && input.size()%9 ==0){
216         using namespace Geom;
217         for( unsigned n=0; n<input.size();  ){
218             CrossingPoint cp;
219             cp.pt[X] = input[n++];
220             cp.pt[Y] = input[n++];
221             cp.i = input[n++];
222             cp.j = input[n++];
223             cp.ni = input[n++];
224             cp.nj = input[n++];
225             cp.ti = input[n++];
226             cp.tj = input[n++];
227             cp.sign = input[n++];
228             push_back(cp);
229         }
230     }
233 std::vector<double>
234 CrossingPoints::to_vector()
236     using namespace Geom;
237     std::vector<double> result;
238     for( unsigned n=0; n<size(); n++){
239         CrossingPoint cp = (*this)[n];
240         result.push_back(cp.pt[X]);
241         result.push_back(cp.pt[Y]);
242         result.push_back(double(cp.i));
243         result.push_back(double(cp.j));
244         result.push_back(double(cp.ni));
245         result.push_back(double(cp.nj));
246         result.push_back(double(cp.ti));
247         result.push_back(double(cp.tj));
248         result.push_back(double(cp.sign));
249     }
250     return result;
253 //FIXME: rewrite to check success: return bool, put result in arg.
254 CrossingPoint
255 CrossingPoints::get(unsigned const i, unsigned const ni)
257     for (unsigned k=0; k<size(); k++){
258         if (
259             ((*this)[k].i==i && (*this)[k].ni==ni) ||
260             ((*this)[k].j==i && (*this)[k].nj==ni)
261             ) return (*this)[k];
262     }
263     g_warning("LPEKnotNS::CrossingPoints::get error. %uth crossing along string %u not found.",ni,i);
264     assert(false);//debug purpose...
265     return CrossingPoint();
268 unsigned
269 idx_of_nearest(CrossingPoints const &cpts, Geom::Point const &p)
271     double dist=-1;
272     unsigned result = cpts.size();
273     for (unsigned k=0; k<cpts.size(); k++){
274         double dist_k = Geom::L2(p-cpts[k].pt);
275         if (dist<0 || dist>dist_k){
276             result = k;
277             dist = dist_k;
278         }
279     }
280     return result;
283 //TODO: Find a way to warn the user when the topology changes.
284 //TODO: be smarter at guessing the signs when the topology changed?
285 void
286 CrossingPoints::inherit_signs(CrossingPoints const &other, int default_value)
288     bool topo_changed = false;
289     for (unsigned n=0; n<size(); n++){
290         if ( n<other.size() &&
291              other[n].i  == (*this)[n].i  &&
292              other[n].j  == (*this)[n].j  &&
293              other[n].ni == (*this)[n].ni &&
294              other[n].nj == (*this)[n].nj    )
295         {
296             (*this)[n].sign = other[n].sign;
297         }else{
298             topo_changed = true;
299             break;
300         }
301     }
302     if (topo_changed){
303         //TODO: Find a way to warn the user!!
304 //        std::cout<<"knot topolgy changed!\n";
305         for (unsigned n=0; n<size(); n++){
306             Geom::Point p = (*this)[n].pt;
307             unsigned idx = idx_of_nearest(other,p);
308             if (idx<other.size()){
309                 (*this)[n].sign = other[idx].sign;
310             }else{
311                 (*this)[n].sign = default_value;
312             }
313         }
314     }
319 //---------------------------------------------------------------------------
320 //---------------------------------------------------------------------------
321 //LPEKnot effect.
322 //---------------------------------------------------------------------------
323 //---------------------------------------------------------------------------
326 LPEKnot::LPEKnot(LivePathEffectObject *lpeobject) :
327     Effect(lpeobject),
328     // initialise your parameters here:
329     interruption_width(_("Fixed width"), _("Size of hidden region of lower string"), "interruption_width", &wr, this, 3),
330     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),
331     add_stroke_width(_("Stroke width"), _("Add the stroke width to the interruption size"), "add_stroke_width", &wr, this, true),
332     add_other_stroke_width(_("Crossing path stroke width"), _("Add crossed stroke width to the interruption size"), "add_other_stroke_width", &wr, this, true),
333     switcher_size(_("Switcher size"), _("Orientation indicator/switcher size"), "switcher_size", &wr, this, 15),
334     crossing_points_vector(_("Crossing Signs"), _("Crossings signs"), "crossing_points_vector", &wr, this),
335     gpaths(),gstroke_widths()
337     // register all your parameters here, so Inkscape knows which parameters this effect has:
338     registerParameter( dynamic_cast<Parameter *>(&interruption_width) );
339     registerParameter( dynamic_cast<Parameter *>(&prop_to_stroke_width) );
340     registerParameter( dynamic_cast<Parameter *>(&add_stroke_width) );
341     registerParameter( dynamic_cast<Parameter *>(&add_other_stroke_width) );
342     registerParameter( dynamic_cast<Parameter *>(&switcher_size) );
343     registerParameter( dynamic_cast<Parameter *>(&crossing_points_vector) );
345     registerKnotHolderHandle(new KnotHolderEntityCrossingSwitcher(), _("Drag to select a crossing, click to flip it"));
346     crossing_points = LPEKnotNS::CrossingPoints();
347     selectedCrossing = 0;
348     switcher = Geom::Point(0,0);
351 LPEKnot::~LPEKnot()
356 void
357 LPEKnot::updateSwitcher(){
358     if (selectedCrossing < crossing_points.size()){
359         switcher = crossing_points[selectedCrossing].pt;
360         //std::cout<<"placing switcher at "<<switcher<<" \n";
361     }else if (crossing_points.size()>0){
362         selectedCrossing = 0;
363         switcher = crossing_points[selectedCrossing].pt;
364         //std::cout<<"placing switcher at "<<switcher<<" \n";
365     }else{
366         //std::cout<<"hiding switcher!\n";
367         //TODO: is there a way to properly hide the helper.
368         //switcher = Geom::Point(Geom::infinity(),Geom::infinity());
369         switcher = Geom::Point(1e10,1e10);
370     }
373 std::vector<Geom::Path>
374 LPEKnot::doEffect_path (std::vector<Geom::Path> const &path_in)
376     using namespace Geom;
377     std::vector<Geom::Path> path_out;
379     if (gpaths.size()==0){
380         return path_in;
381     }
383     for (unsigned comp=0; comp<path_in.size(); comp++){
385         //find the relevant path component in gpaths (required to allow groups!)
386         //Q: do we always recieve the group members in the same order? can we rest on that?
387         unsigned i0 = 0;
388         for (i0=0; i0<gpaths.size(); i0++){
389             if (path_in[comp]==gpaths[i0]) break;
390         }
391         if (i0 == gpaths.size() ) {THROW_EXCEPTION("lpe-knot error: group member not recognized");}// this should not happen...
393         std::vector<Interval> dom;
394         dom.push_back(Interval(0.,gpaths[i0].size()));
395         for (unsigned p = 0; p < crossing_points.size(); p++){
396             if (crossing_points[p].i == i0 || crossing_points[p].j == i0){
397                 unsigned i = crossing_points[p].i;
398                 unsigned j = crossing_points[p].j;
399                 double ti = crossing_points[p].ti;
400                 double tj = crossing_points[p].tj;
401                 
402                 double curveidx, t;
403                 
404                 t = modf(ti, &curveidx);
405                 if(curveidx == gpaths[i].size() ) { curveidx--; t = 1.;}
406                 assert(curveidx >= 0 && curveidx < gpaths[i].size());
407                 std::vector<Point> flag_i = gpaths[i][curveidx].pointAndDerivatives(t,1);
409                 t = modf(tj, &curveidx);
410                 if(curveidx == gpaths[j].size() ) { curveidx--; t = 1.;}
411                 assert(curveidx >= 0 && curveidx < gpaths[j].size());
412                 std::vector<Point> flag_j = gpaths[j][curveidx].pointAndDerivatives(t,1);
415                 int geom_sign = ( cross(flag_i[1],flag_j[1]) > 0 ? 1 : -1);
417                 bool i0_is_under = false;
418                 if ( crossing_points[p].sign * geom_sign > 0 ){
419                     i0_is_under = ( i == i0 );
420                 }else if ( crossing_points[p].sign * geom_sign < 0 ){
421                     if (j == i0){
422                         std::swap( i, j);
423                         std::swap(ti, tj);
424                         std::swap(flag_i,flag_j);
425                         i0_is_under = true;
426                     }
427                 }
428                 if (i0_is_under){
429                     double width = interruption_width;
430                     if ( prop_to_stroke_width.get_value() ) {
431                         width *= gstroke_widths[i];
432                     }
433                     if ( add_stroke_width.get_value() ) {
434                         width += gstroke_widths[i];
435                     }
436                     if ( add_other_stroke_width.get_value() ) {
437                         width += gstroke_widths[j];
438                     }
439                     Interval hidden = findShadowedTime(gpaths[i0], flag_j, ti, width/2);
440                     double period  = gpaths[i0].size();//hm... Should this be gpaths[i0].size()+1?
441                     if (hidden.max() > period ) hidden -= period;
442                     if (hidden.min()<0){
443                         dom = complementOf( Interval(0,hidden.max()) ,dom);
444                         dom = complementOf( Interval(hidden.min()+period, period) ,dom);
445                     }else{
446                         dom = complementOf(hidden,dom);
447                     }
448                 }
449             }
450         }
452         //If the all component is hidden, continue.
453         if ( dom.size() == 0){
454             continue;
455         }
457         //If the current path is closed and the last/first point is still there, glue first and last piece.
458         unsigned beg_comp = 0, end_comp = dom.size();
459         if ( gpaths[i0].closed() && dom.front().min() == 0 && dom.back().max() ==  gpaths[i0].size() ){
460             if ( dom.size() == 1){
461                 path_out.push_back(gpaths[i0]);
462                 continue;
463             }else{
464 //                std::cout<<"fusing first and last component\n";
465                 beg_comp++;
466                 end_comp--;
467                 Path first = gpaths[i0].portion(dom.back());
468                 //FIXME: STITCH_DISCONTINUOUS should not be necessary (?!?)
469                 first.append(gpaths[i0].portion(dom.front()), Path::STITCH_DISCONTINUOUS);
470                 path_out.push_back(first);
471             }
472         }
473         for (unsigned comp = beg_comp; comp < end_comp; comp++){
474             assert(dom.at(comp).min() >=0 and dom.at(comp).max() <= gpaths.at(i0).size());
475             path_out.push_back(gpaths[i0].portion(dom.at(comp)));
476         }
477     }
478     return path_out;
483 //recursively collect gpaths and stroke widths (stolen from "sp-lpe_item.cpp").
484 void collectPathsAndWidths (SPLPEItem const *lpeitem, std::vector<Geom::Path> &paths, std::vector<double> &stroke_widths){
485     if (SP_IS_GROUP(lpeitem)) {
486         GSList const *item_list = sp_item_group_item_list(SP_GROUP(lpeitem));
487         for ( GSList const *iter = item_list; iter; iter = iter->next ) {
488             SPObject *subitem = static_cast<SPObject *>(iter->data);
489             if (SP_IS_LPE_ITEM(subitem)) {
490                 collectPathsAndWidths(SP_LPE_ITEM(subitem), paths, stroke_widths);
491             }
492         }
493     }
494     else if (SP_IS_SHAPE(lpeitem)) {
495         SPCurve * c = NULL;
496         if (SP_IS_PATH(lpeitem)) {
497             c = sp_path_get_curve_for_edit(SP_PATH(lpeitem));
498         } else {
499             c = sp_shape_get_curve(SP_SHAPE(lpeitem));
500         }
501         if (c) {
502             Geom::PathVector subpaths = c->get_pathvector();
503             for (unsigned i=0; i<subpaths.size(); i++){
504                 paths.push_back(subpaths[i]);
505                 //FIXME: do we have to be more carefull when trying to access stroke width?
506                 stroke_widths.push_back(SP_ITEM(lpeitem)->style->stroke_width.computed);
507             }
508         }
509     }
513 void
514 LPEKnot::doBeforeEffect (SPLPEItem *lpeitem)
516     using namespace Geom;
517     original_bbox(lpeitem);
519     gpaths = std::vector<Geom::Path>();
520     gstroke_widths = std::vector<double>();
521     collectPathsAndWidths(lpeitem, gpaths, gstroke_widths);
523 //     std::cout<<"\nPaths on input:\n";
524 //     for (unsigned i=0; i<gpaths.size(); i++){
525 //         for (unsigned ii=0; ii<gpaths[i].size(); ii++){
526 //             std::cout << gpaths[i][ii].toSBasis()[Geom::X] <<"\n";
527 //             std::cout << gpaths[i][ii].toSBasis()[Geom::Y] <<"\n";
528 //             std::cout<<"--\n";
529 //         }
530 //     }
531                         
532     //std::cout<<"crossing_pts_vect: "<<crossing_points_vector.param_getSVGValue()<<".\n";
533     //std::cout<<"prop_to_stroke_width: "<<prop_to_stroke_width.param_getSVGValue()<<".\n";
535     LPEKnotNS::CrossingPoints old_crdata(crossing_points_vector.data());
537 //     std::cout<<"\nVectorParam size:"<<crossing_points_vector.data().size()<<"\n";
539 //     std::cout<<"\nOld crdata ("<<old_crdata.size()<<"): \n";
540 //     for (unsigned toto=0; toto<old_crdata.size(); toto++){
541 //         std::cout<<"(";
542 //         std::cout<<old_crdata[toto].i<<",";
543 //         std::cout<<old_crdata[toto].j<<",";
544 //         std::cout<<old_crdata[toto].ni<<",";
545 //         std::cout<<old_crdata[toto].nj<<",";
546 //         std::cout<<old_crdata[toto].ti<<",";
547 //         std::cout<<old_crdata[toto].tj<<",";
548 //         std::cout<<old_crdata[toto].sign<<"),";
549 //     }
551     //if ( old_crdata.size() > 0 ) std::cout<<"first crossing sign = "<<old_crdata[0].sign<<".\n";
552     //else std::cout<<"old data is empty!!\n";
553     crossing_points = LPEKnotNS::CrossingPoints(gpaths);
554 //     std::cout<<"\nNew crdata ("<<crossing_points.size()<<"): \n";
555 //     for (unsigned toto=0; toto<crossing_points.size(); toto++){
556 //         std::cout<<"(";
557 //         std::cout<<crossing_points[toto].i<<",";
558 //         std::cout<<crossing_points[toto].j<<",";
559 //         std::cout<<crossing_points[toto].ni<<",";
560 //         std::cout<<crossing_points[toto].nj<<",";
561 //         std::cout<<crossing_points[toto].ti<<",";
562 //         std::cout<<crossing_points[toto].tj<<",";
563 //         std::cout<<crossing_points[toto].sign<<"),";
564 //     }
565     crossing_points.inherit_signs(old_crdata);
566     crossing_points_vector.param_set_and_write_new_value(crossing_points.to_vector());
567     updateSwitcher();
571 static LPEKnot *
572 get_effect(SPItem *item)
574     Effect *effect = sp_lpe_item_get_current_lpe(SP_LPE_ITEM(item));
575     if (effect->effectType() != KNOT) {
576         g_print ("Warning: Effect is not of type LPEKnot!\n");
577         return NULL;
578     }
579     return static_cast<LPEKnot *>(effect);
582 void
583 LPEKnot::addCanvasIndicators(SPLPEItem */*lpeitem*/, std::vector<Geom::PathVector> &hp_vec)
585     using namespace Geom;
586     double r = switcher_size*.1;
587     char const * svgd;
588     //TODO: use a nice path!
589     if (selectedCrossing >= crossing_points.size()||crossing_points[selectedCrossing].sign > 0){
590         //svgd = "M -10,0 A 10 10 0 1 0 0,-10 l  5,-1 -1,2";
591         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";
592     }else if (crossing_points[selectedCrossing].sign < 0){
593         //svgd = "M  10,0 A 10 10 0 1 1 0,-10 l -5,-1  1,2";
594         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";
595     }else{
596         //svgd = "M 10,0 A 10 10 0 1 0 -10,0 A 10 10 0 1 0 10,0 ";
597         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";
598     }
599     PathVector pathv = sp_svg_read_pathv(svgd);
600     pathv *= Matrix(r,0,0,r,0,0);
601     pathv+=switcher;
602     hp_vec.push_back(pathv);
605 void
606 KnotHolderEntityCrossingSwitcher::knot_set(Geom::Point const &p, Geom::Point const &/*origin*/, guint /*state*/)
608     LPEKnot* lpe = get_effect(item);
610     lpe->selectedCrossing = idx_of_nearest(lpe->crossing_points,p);
611     lpe->updateSwitcher();
612     // FIXME: this should not directly ask for updating the item. It should write to SVG, which triggers updating.
613     sp_lpe_item_update_patheffect (SP_LPE_ITEM(item), false, true);
616 Geom::Point
617 KnotHolderEntityCrossingSwitcher::knot_get()
619     LPEKnot* lpe = get_effect(item);
620     return snap_knot_position(lpe->switcher);
623 void
624 KnotHolderEntityCrossingSwitcher::knot_click(guint state)
626     LPEKnot* lpe = get_effect(item);
627     unsigned s = lpe->selectedCrossing;
628     if (s < lpe->crossing_points.size()){
629         if (state & GDK_SHIFT_MASK){
630             lpe->crossing_points[s].sign = 1;
631         }else{
632             int sign = lpe->crossing_points[s].sign;
633             lpe->crossing_points[s].sign = ((sign+2)%3)-1;
634             //std::cout<<"crossing set to"<<lpe->crossing_points[s].sign<<".\n";
635         }
636         lpe->crossing_points_vector.param_set_and_write_new_value(lpe->crossing_points.to_vector());
637         sp_document_done(lpe->getSPDoc(), SP_VERB_DIALOG_LIVE_PATH_EFFECT, /// @todo Is this the right verb?
638                  _("Change knot crossing"));
640         // FIXME: this should not directly ask for updating the item. It should write to SVG, which triggers updating.
641 //        sp_lpe_item_update_patheffect (SP_LPE_ITEM(item), false, true);
642     }
646 /* ######################## */
648 } // namespace LivePathEffect
649 } // namespace Inkscape
651 /*
652   Local Variables:
653   mode:c++
654   c-file-style:"stroustrup"
655   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
656   indent-tabs-mode:nil
657   fill-column:99
658   End:
659 */
660 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :