Transform of horizontal or vertical line with width 0 broken

If you have a line which has a zero width (Typically your horizontal or vertical lines) and you transform the line becomes corrupt.

Still happens on 7.9 release

To reproduce:

  1. make a vertical or horizontal line (use ctrl to make sure it is vertical or horizontal) and call it “Line”
  2. create a button with following code
line=event.source.parent.getComponent('Line')
line.setRelX(100)
line.setRelY(20)
line.setRelWidth(100)
line.setRelHeight(100)
  1. And execute…you will see the line disappear.

The line object will have the right properties but report as a Shape “Line” (NaN,20),[Nan,100]

You cannot correct this object anymore to get it visible… only solution is to delete and recreate line

  1. If you use a non zero width line and rotate to vertical and horizontal it works…it appears to happen only when width or height is 0

  2. Same happens if you use other transformations eg system.gui.transform or the older resizeComponent on the line, so there appears to be no workaround

In my usage case I have complex pages with very large object count that are being ported onto a new server build with new page layout. Things had moved around when importing to new container so I’d written function to save component positions on original window and restore on new machine in new container…all good except for these lines disappearing. If I can get this working it will save me hours.

I fudged a workaround that got me out of trouble…if the width was 0, I set it to 1 and then applied the transform.

Could not set width to 0 afterwards due to the disappearance issue, but it worked for what I needed and saved my hours of rejigging components.

I’ve posted my very, very ugly code below in case it is of use to someone.

import pickle

def storePosition(object):
	#root container to begin from
	root=object
	

		
	#now get all components
	components=[]
	objs=root.getComponents()
	descend=[]
	for c in objs:
		if c.getName():
			components.append(("",c))
			descend.append(("",c))
	
	while len(descend)>0:
		objs=descend[0][1].getComponents()
		for c in objs:
			if c.getName():
				if descend[0][0]=="":
					prefix=""
				else:
					prefix=descend[0][0]+"/"
				components.append((prefix+descend[0][1].getName(),c))
				descend.append((prefix+descend[0][1].getName(),c))
		descend=descend[1:] #drop one of the list
	print len(components)
	#create dictionary of name,position and size
	d={}
	for cc in components:
		
		c=cc[1]
		try:
			x=c.getX()
		except:
			x=None
		try:
			y=c.getY()
		except:
			y=None
		try:
			w=c.width
		except:
			w=None
		try:
			h=c.height
		except:
			h=None
		try:
			rx=c.relX
		except:
			rx=None
		try:
			ry=c.relY
		except:
			ry=None
		try:
			rw=c.relWidth
		except:
			rw=None
		try:
			rh=c.relHeight
		except:
			rh=None
		
		try:
			ang=c.angleDegrees
		except:
			ang=None
		
		if cc[0]=="":
			prefix=""
		else:
			prefix=cc[0]+"/"
		
		
		d[prefix+c.getName()]=(x,y,w,h,rx,ry,rw,rh,ang,type(c))
		print prefix+c.getName(),(x,y,w,h,rx,ry,rw,rh,ang,type(c))
		
	
	out=pickle.dumps(d)
	path = system.file.saveFile("save_Positions.txt")
	if path != None:
	   system.file.writeFile(path, out)
		
	



def restorePosition(object):
	path = system.file.openFile('txt')
	if path != None:
		data=system.file.readFileAsString(path,"US-ASCII")
   
	
	
	try:
		data=pickle.loads(data)
	except:
		system.gui.errorBox("Error reading file "+path)
		return
	
	
						
	for key in data:
		k=key.split("/")
		co=object
		for kn in k:
			try:
				co=co.getComponent(kn)
			except:
				pass
		
		if co:
			
			name=co.getName()
			#print key,":",name
			if name!=k[-1]: #we may not be a component so stay stuck up the tree
				continue
			x,y,w,h,rx,ry,rw,rh,ang,typ=data[key]
			#do things one at a time
			
			
			
			if x!=None and rx==None:
					#if rx==None:
						#system.gui.transform(co,newX=x,newY=y,newWidth=w,newHeight=h)
						system.gui.moveComponent(co, x, y)
						system.gui.resizeComponent(co, w, h)

					
			
			
			if rx!=None:
				
				if (co.relWidth==0 or co.relHeight==0):
					print "OFFENDING object found"
					print name,x,y,w,h,rx,ry,rw,rh,ang,str(typ)
					if co.width==0:
						co.setRelWidth(1) #force it to have a width or height
					elif co.height==0:
						co.setRelHeight(1)
				#system.gui.transform(co,newX=rx,newY=ry,newWidthr=w,newHeight=rh)
			
				#system.gui.moveComponent(co, int(rx), int(ry))
				#system.gui.resizeComponent(co, int(rw), int(rh))
				co.setRelX(rx)
				co.setRelY(ry)
				co.setAngleDegrees(ang) #force it to have a width or height
				if rw==0:
					co.setRelHeight(rh)
					#co.setRelWidth(rw)
				elif rh==0:
					co.setRelWidth(rw)
					#co.setRelHeight(rh)
				else:
					co.setRelWidth(rw)
					co.setRelHeight(rh)
				
				
				
							
			
					
			
					
								
			
		else:
			name="NOT FOUND"