Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
TASTE
OpenGEODE
Commits
b5976aa5
Commit
b5976aa5
authored
Aug 07, 2016
by
Maxime Perrotin
Browse files
Fix positionning issues when loading
parent
61fa2ebe
Changes
1
Hide whitespace changes
Inline
Side-by-side
opengeode/opengeode.py
View file @
b5976aa5
...
...
@@ -545,50 +545,53 @@ class SDL_Scene(QtGui.QGraphicsScene, object):
G_SYMBOLS
.
add
(
each
)
# Refreshing the scene may result in resizing some symbols
dest_scene
.
refresh
()
for
each
in
dest_scene
.
floating_symb
:
# Once everything is rendered, adjust position of each
# symbol to the value from the AST (positions may be
# slightly altered by the reshaping functions)
def
fix_pos_from_ast
(
symbol
):
try
:
if
symbol
.
ast
.
pos_x
and
symbol
.
ast
.
pos_y
:
relpos
=
symbol
.
mapFromScene
(
symbol
.
ast
.
pos_x
,
symbol
.
ast
.
pos_y
)
symbol
.
pos_x
+=
relpos
.
x
()
symbol
.
pos_y
+=
relpos
.
y
()
symbol
.
update_connections
()
# Update_position is called here because it
# 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
()
# Once everything is rendered, adjust position of each
# symbol to the value from the AST (positions may be
# slightly altered by the reshaping functions)
def
fix_pos_from_ast
(
symbol
):
try
:
if
symbol
.
ast
.
pos_x
and
symbol
.
ast
.
pos_y
:
relpos
=
symbol
.
mapFromScene
(
symbol
.
ast
.
pos_x
,
symbol
.
ast
.
pos_y
)
#symbol.pos_x += relpos.x()
#symbol.pos_y += relpos.y()
if
not
symbol
.
hasParent
:
symbol
.
pos_x
=
symbol
.
ast
.
pos_x
symbol
.
pos_y
=
symbol
.
ast
.
pos_y
else
:
# No CIF coordinates: fix COMMENT position
if
isinstance
(
symbol
,
genericSymbols
.
Comment
):
symbol
.
pos_x
=
\
symbol
.
parent
.
boundingRect
().
width
()
+
15
symbol
.
pos_y
=
0
if
not
symbol
.
hasParent
:
#print 'Positionning', unicode(symbol)[slice(0,20)]
sc_br
=
dest_scene
.
itemsBoundingRect
()
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
symbol
.
position
+=
relpos
symbol
.
update_connections
()
# Update_position is called here because it
# 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
:
# 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
)
fix_pos_from_ast
(
each
)
# No CIF coordinates: fix COMMENT position
if
isinstance
(
symbol
,
genericSymbols
.
Comment
):
symbol
.
pos_x
=
\
symbol
.
parent
.
boundingRect
().
width
()
+
15
symbol
.
pos_y
=
0
if
not
symbol
.
hasParent
:
sc_br
=
dest_scene
.
itemsBoundingRect
()
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
:
LOG
.
error
(
traceback
.
format_exc
())
...
...
@@ -691,8 +694,8 @@ class SDL_Scene(QtGui.QGraphicsScene, object):
in order to avoid negative coordinates
'''
try
:
min_x
=
min
(
item
.
x
()
for
item
in
self
.
floating
_symb
)
min_y
=
min
(
item
.
y
()
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
.
visible
_symb
)
except
ValueError
:
# No item in the scene
return
0
,
0
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment