Commit b5976aa5 authored by Maxime Perrotin's avatar Maxime Perrotin
Browse files

Fix positionning issues when loading

parent 61fa2ebe
...@@ -545,50 +545,53 @@ class SDL_Scene(QtGui.QGraphicsScene, object): ...@@ -545,50 +545,53 @@ class SDL_Scene(QtGui.QGraphicsScene, object):
G_SYMBOLS.add(each) G_SYMBOLS.add(each)
# Refreshing the scene may result in resizing some symbols # Refreshing the scene may result in resizing some symbols
dest_scene.refresh() dest_scene.refresh()
for each in dest_scene.floating_symb: # Once everything is rendered, adjust position of each
# Once everything is rendered, adjust position of each # symbol to the value from the AST (positions may be
# symbol to the value from the AST (positions may be # slightly altered by the reshaping functions)
# slightly altered by the reshaping functions) def fix_pos_from_ast(symbol):
def fix_pos_from_ast(symbol): try:
try: if symbol.ast.pos_x and symbol.ast.pos_y:
if symbol.ast.pos_x and symbol.ast.pos_y: relpos = symbol.mapFromScene(symbol.ast.pos_x,
relpos = symbol.mapFromScene(symbol.ast.pos_x, symbol.ast.pos_y)
symbol.ast.pos_y) #symbol.pos_x += relpos.x()
symbol.pos_x += relpos.x() #symbol.pos_y += relpos.y()
symbol.pos_y += relpos.y() if not symbol.hasParent:
symbol.update_connections() symbol.pos_x = symbol.ast.pos_x
# Update_position is called here because it symbol.pos_y = symbol.ast.pos_y
# is not possible to be sure that the
# positionning stored in the file will be
# rendered correctly on the host plaform.
# Font rendering may cause slight differences
# between Linux and Windows for example.
symbol.update_position()
else: else:
# No CIF coordinates: fix COMMENT position symbol.position += relpos
if isinstance(symbol, genericSymbols.Comment): symbol.update_connections()
symbol.pos_x = \ # Update_position is called here because it
symbol.parent.boundingRect().width() + 15 # is not possible to be sure that the
symbol.pos_y = 0 # positionning stored in the file will be
if not symbol.hasParent: # rendered correctly on the host plaform.
#print 'Positionning', unicode(symbol)[slice(0,20)] # Font rendering may cause slight differences
sc_br = dest_scene.itemsBoundingRect() # between Linux and Windows for example.
sy_br = symbol.mapRectToScene( symbol.update_position()
symbol.boundingRect() |
symbol.childrenBoundingRect())
symbol.pos_x += (sc_br.width() - sy_br.x())
except AttributeError:
# no AST, ignore (e.g. Connections, Cornergrabbers)
pass
else: else:
# Recursively fix pos of sub branches and followers # No CIF coordinates: fix COMMENT position
for branch in (elm for elm in symbol.childSymbols() if isinstance(symbol, genericSymbols.Comment):
if isinstance(elm, symbol.pos_x = \
genericSymbols.HorizontalSymbol)): symbol.parent.boundingRect().width() + 15
fix_pos_from_ast(branch) symbol.pos_y = 0
fix_pos_from_ast(symbol.next_aligned_symbol()) if not symbol.hasParent:
fix_pos_from_ast(symbol.comment) sc_br = dest_scene.itemsBoundingRect()
fix_pos_from_ast(each) sy_br = symbol.mapRectToScene(
symbol.boundingRect() |
symbol.childrenBoundingRect())
symbol.pos_x += (sc_br.width() - sy_br.x())
except AttributeError:
# no AST, ignore (e.g. Connections, Cornergrabbers)
pass
else:
# Recursively fix pos of sub branches and followers
for branch in (elm for elm in symbol.childSymbols()
if isinstance(elm,
genericSymbols.HorizontalSymbol)):
fix_pos_from_ast(branch)
fix_pos_from_ast(symbol.next_aligned_symbol())
fix_pos_from_ast(symbol.comment)
map(fix_pos_from_ast, dest_scene.floating_symb)
except TypeError: except TypeError:
LOG.error(traceback.format_exc()) LOG.error(traceback.format_exc())
...@@ -691,8 +694,8 @@ class SDL_Scene(QtGui.QGraphicsScene, object): ...@@ -691,8 +694,8 @@ class SDL_Scene(QtGui.QGraphicsScene, object):
in order to avoid negative coordinates in order to avoid negative coordinates
''' '''
try: try:
min_x = min(item.x() for item in self.floating_symb) min_x = min(item.x() for item in self.visible_symb)
min_y = min(item.y() for item in self.floating_symb) min_y = min(item.y() for item in self.visible_symb)
except ValueError: except ValueError:
# No item in the scene # No item in the scene
return 0, 0 return 0, 0
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment