From: acspike Date: Thu, 29 Mar 2007 02:35:11 +0000 (+0000) Subject: fix bug [ 1685070 ] PathAlongPath - Error message when no paths selected X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=a6c2ef55f2c36eb460633bc4c9cbc96f1b7ba34f;p=inkscape.git fix bug [ 1685070 ] PathAlongPath - Error message when no paths selected --- diff --git a/share/extensions/pathalongpath.py b/share/extensions/pathalongpath.py index ba4534b13..af42a2dee 100644 --- a/share/extensions/pathalongpath.py +++ b/share/extensions/pathalongpath.py @@ -38,11 +38,11 @@ import copy, math, re, random, xml.xpath def flipxy(path): for pathcomp in path: - for ctl in pathcomp: - for pt in ctl: - tmp=pt[0] - pt[0]=-pt[1] - pt[1]=-tmp + for ctl in pathcomp: + for pt in ctl: + tmp=pt[0] + pt[0]=-pt[1] + pt[1]=-tmp def offset(pathcomp,dx,dy): for ctl in pathcomp: @@ -69,19 +69,19 @@ def linearize(p,tolerance=0.001): d=0 lengths=[] while i tolerance: - b1, b2 = bezmisc.beziersplitatt([p[i][1],p[i][2],p[i+1][0],p[i+1][1]], 0.5) - p[i ][2][0],p[i ][2][1]=b1[1] - p[i+1][0][0],p[i+1][0][1]=b2[2] - p.insert(i+1,[[b1[2][0],b1[2][1]],[b1[3][0],b1[3][1]],[b2[1][0],b2[1][1]]]) - else: - d=(box+chord)/2 - lengths.append(d) - i+=1 + box = bezmisc.pointdistance(p[i ][1],p[i ][2]) + box += bezmisc.pointdistance(p[i ][2],p[i+1][0]) + box += bezmisc.pointdistance(p[i+1][0],p[i+1][1]) + chord = bezmisc.pointdistance(p[i][1], p[i+1][1]) + if (box - chord) > tolerance: + b1, b2 = bezmisc.beziersplitatt([p[i][1],p[i][2],p[i+1][0],p[i+1][1]], 0.5) + p[i ][2][0],p[i ][2][1]=b1[1] + p[i+1][0][0],p[i+1][0][1]=b2[2] + p.insert(i+1,[[b1[2][0],b1[2][1]],[b1[3][0],b1[3][1]],[b2[1][0],b2[1][1]]]) + else: + d=(box+chord)/2 + lengths.append(d) + i+=1 new=[p[i][1] for i in range(0,len(p)-1) if lengths[i]>zero] new.append(p[-1][1]) lengths=[l for l in lengths if l>zero] @@ -118,149 +118,152 @@ class PathAlongPath(pathmodifier.Diffeo): help="duplicate pattern before deformation") def prepareSelectionList(self): -##first selected->pattern, all but first selected-> skeletons + ##first selected->pattern, all but first selected-> skeletons id = self.options.ids[-1] - self.patterns={id:self.selected[id]} - if self.options.duplicate: - self.patterns=self.duplicateNodes(self.patterns) + self.patterns={id:self.selected[id]} + if self.options.duplicate: + self.patterns=self.duplicateNodes(self.patterns) self.expandGroupsUnlinkClones(self.patterns, True, True) - self.objectsToPaths(self.patterns) - del self.selected[id] + self.objectsToPaths(self.patterns) + del self.selected[id] self.skeletons=self.selected self.expandGroupsUnlinkClones(self.skeletons, True, False) - self.objectsToPaths(self.skeletons) + self.objectsToPaths(self.skeletons) def lengthtotime(self,l): - ''' - Recieves an arc length l, and returns the index of the segment in self.skelcomp - containing the coresponding point, to gether with the position of the point on this segment. - - If the deformer is closed, do computations modulo the toal length. - ''' - if self.skelcompIsClosed: - l=l % sum(self.lengths) - if l<=0: - return 0,l/self.lengths[0] - i=0 - while (i----> TODO: really test if path is closed! end point==start point is not enough! - self.skelcompIsClosed = (self.skelcomp[0]==self.skelcomp[-1]) - - length=sum(self.lengths) - xoffset=self.skelcomp[0][0]-bbox[0]+self.options.toffset - yoffset=self.skelcomp[0][1]-(bbox[2]+bbox[3])/2-self.options.noffset - - if self.options.repeat: - NbCopies=max(1,int(round((length+self.options.space)/dx))) - width=dx*NbCopies - if not self.skelcompIsClosed: - width-=self.options.space - bbox=bbox[0],bbox[0]+width,bbox[2],bbox[3] - new=[] - for sub in p: - for i in range(0,NbCopies,1): - new.append(copy.deepcopy(sub)) - offset(sub,dx,0) - p=new - - for sub in p: - offset(sub,xoffset,yoffset) - - if self.options.stretch: - for sub in p: - stretch(sub,length/width,1,self.skelcomp[0]) - - for sub in p: - for ctlpt in sub: - self.applyDiffeo(ctlpt[1],(ctlpt[0],ctlpt[2])) - - if self.options.vertical: - flipxy(p) - newp+=p - - d.value = cubicsuperpath.formatPath(newp) + flipxy(p0) + + newp=[] + for skelnode in self.skeletons.itervalues(): + self.curSekeleton=cubicsuperpath.parsePath(skelnode.getAttribute('d')) + if self.options.vertical: + flipxy(self.curSekeleton) + for comp in self.curSekeleton: + p=copy.deepcopy(p0) + self.skelcomp,self.lengths=linearize(comp) + #!!!!>----> TODO: really test if path is closed! end point==start point is not enough! + self.skelcompIsClosed = (self.skelcomp[0]==self.skelcomp[-1]) + + length=sum(self.lengths) + xoffset=self.skelcomp[0][0]-bbox[0]+self.options.toffset + yoffset=self.skelcomp[0][1]-(bbox[2]+bbox[3])/2-self.options.noffset + + if self.options.repeat: + NbCopies=max(1,int(round((length+self.options.space)/dx))) + width=dx*NbCopies + if not self.skelcompIsClosed: + width-=self.options.space + bbox=bbox[0],bbox[0]+width,bbox[2],bbox[3] + new=[] + for sub in p: + for i in range(0,NbCopies,1): + new.append(copy.deepcopy(sub)) + offset(sub,dx,0) + p=new + + for sub in p: + offset(sub,xoffset,yoffset) + + if self.options.stretch: + for sub in p: + stretch(sub,length/width,1,self.skelcomp[0]) + + for sub in p: + for ctlpt in sub: + self.applyDiffeo(ctlpt[1],(ctlpt[0],ctlpt[2])) + + if self.options.vertical: + flipxy(p) + newp+=p + + d.value = cubicsuperpath.formatPath(newp) e = PathAlongPath() e.affect() - +