diff options
| author | Aaron Spike <aaron@ekips.org> | 2007-03-29 02:35:11 +0000 |
|---|---|---|
| committer | acspike <acspike@users.sourceforge.net> | 2007-03-29 02:35:11 +0000 |
| commit | 72a88bfef9026a679da0d1f4ca8ba754b24a0f01 (patch) | |
| tree | 08a37d18c8a18ddd0a9352c168b1069ac94f9bb1 | |
| parent | Fix for #1684042 (undo while adding a shape with the mouse results in a crash.) (diff) | |
| download | inkscape-72a88bfef9026a679da0d1f4ca8ba754b24a0f01.tar.gz inkscape-72a88bfef9026a679da0d1f4ca8ba754b24a0f01.zip | |
fix bug [ 1685070 ] PathAlongPath - Error message when no paths selected
(bzr r2775)
| -rw-r--r-- | share/extensions/pathalongpath.py | 277 |
1 files changed, 140 insertions, 137 deletions
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<len(p)-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
+ 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<len(self.lengths)) and (self.lengths[i]<=l):
- l-=self.lengths[i]
- i+=1
- t=l/self.lengths[min(i,len(self.lengths)-1)]
- return i, t
+ '''
+ 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<len(self.lengths)) and (self.lengths[i]<=l):
+ l-=self.lengths[i]
+ i+=1
+ t=l/self.lengths[min(i,len(self.lengths)-1)]
+ return i, t
def applyDiffeo(self,bpt,vects=()):
- '''
- The kernel of this stuff:
- bpt is a base point and for v in vectors, v'=v-p is a tangent vector at bpt.
- '''
+ '''
+ The kernel of this stuff:
+ bpt is a base point and for v in vectors, v'=v-p is a tangent vector at bpt.
+ '''
s=bpt[0]-self.skelcomp[0][0]
- i,t=self.lengthtotime(s)
+ i,t=self.lengthtotime(s)
if i==len(self.skelcomp)-1:
x,y=bezmisc.tpoint(self.skelcomp[i-1],self.skelcomp[i],1+t)
- dx=(self.skelcomp[i][0]-self.skelcomp[i-1][0])/self.lengths[-1]
- dy=(self.skelcomp[i][1]-self.skelcomp[i-1][1])/self.lengths[-1]
+ dx=(self.skelcomp[i][0]-self.skelcomp[i-1][0])/self.lengths[-1]
+ dy=(self.skelcomp[i][1]-self.skelcomp[i-1][1])/self.lengths[-1]
else:
x,y=bezmisc.tpoint(self.skelcomp[i],self.skelcomp[i+1],t)
dx=(self.skelcomp[i+1][0]-self.skelcomp[i][0])/self.lengths[i]
- dy=(self.skelcomp[i+1][1]-self.skelcomp[i][1])/self.lengths[i]
-
- vx=0
- vy=bpt[1]-self.skelcomp[0][1]
- if self.options.wave:
- bpt[0]=x+vx*dx
- bpt[1]=y+vy+vx*dy
- else:
- bpt[0]=x+vx*dx-vy*dy
- bpt[1]=y+vx*dy+vy*dx
-
- for v in vects:
- vx=v[0]-self.skelcomp[0][0]-s
- vy=v[1]-self.skelcomp[0][1]
- if self.options.wave:
- v[0]=x+vx*dx
- v[1]=y+vy+vx*dy
- else:
- v[0]=x+vx*dx-vy*dy
- v[1]=y+vx*dy+vy*dx
+ dy=(self.skelcomp[i+1][1]-self.skelcomp[i][1])/self.lengths[i]
+
+ vx=0
+ vy=bpt[1]-self.skelcomp[0][1]
+ if self.options.wave:
+ bpt[0]=x+vx*dx
+ bpt[1]=y+vy+vx*dy
+ else:
+ bpt[0]=x+vx*dx-vy*dy
+ bpt[1]=y+vx*dy+vy*dx
+
+ for v in vects:
+ vx=v[0]-self.skelcomp[0][0]-s
+ vy=v[1]-self.skelcomp[0][1]
+ if self.options.wave:
+ v[0]=x+vx*dx
+ v[1]=y+vy+vx*dy
+ else:
+ v[0]=x+vx*dx-vy*dy
+ v[1]=y+vx*dy+vy*dx
def effect(self):
- self.prepareSelectionList()
- self.options.wave = (self.options.kind=="Ribbon")
- if self.options.copymode=="Single":
- self.options.repeat =False
- self.options.stretch=False
- elif self.options.copymode=="Repeated":
- self.options.repeat =True
- self.options.stretch=False
- elif self.options.copymode=="Single, stretched":
- self.options.repeat =False
- self.options.stretch=True
- elif self.options.copymode=="Repeated, stretched":
- self.options.repeat =True
- self.options.stretch=True
-
- bbox=self.computeBBox(self.patterns)
- if self.options.vertical:
- #flipxy(bbox)...
- bbox=(-bbox[3],-bbox[2],-bbox[1],-bbox[0])
-
- width=bbox[1]-bbox[0]
- dx=width+self.options.space
+ if len(self.options.ids)<2:
+ inkex.debug("This extension requires that you select two paths.")
+ return
+ self.prepareSelectionList()
+ self.options.wave = (self.options.kind=="Ribbon")
+ if self.options.copymode=="Single":
+ self.options.repeat =False
+ self.options.stretch=False
+ elif self.options.copymode=="Repeated":
+ self.options.repeat =True
+ self.options.stretch=False
+ elif self.options.copymode=="Single, stretched":
+ self.options.repeat =False
+ self.options.stretch=True
+ elif self.options.copymode=="Repeated, stretched":
+ self.options.repeat =True
+ self.options.stretch=True
+
+ bbox=self.computeBBox(self.patterns)
+ if self.options.vertical:
+ #flipxy(bbox)...
+ bbox=(-bbox[3],-bbox[2],-bbox[1],-bbox[0])
+
+ width=bbox[1]-bbox[0]
+ dx=width+self.options.space
for id, node in self.patterns.iteritems():
if node.tagName == 'path':
d = node.attributes.getNamedItem('d')
p0 = cubicsuperpath.parsePath(d.value)
if self.options.vertical:
- 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)
+ 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()
-
+
|
