Skip to content

Commit

Permalink
Flip y-axis on entity graph so geo coordinates work well
Browse files Browse the repository at this point in the history
(cherry picked from commit ae50cf6)
  • Loading branch information
manuelma committed Sep 11, 2023
1 parent d354d0b commit a572700
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
20 changes: 16 additions & 4 deletions spinetoolbox/spine_db_editor/widgets/custom_qgraphicsviews.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,8 +475,14 @@ def save_positions(self, checked=False):
[(class_name, self.pos_x_parameter), (class_name, self.pos_y_parameter)]
)
data.setdefault("object_parameter_values", []).extend(
[(class_name, item.entity_name, self.pos_x_parameter, item.pos().x()) for item in obj_items]
+ [(class_name, item.entity_name, self.pos_y_parameter, item.pos().y()) for item in obj_items]
[
(class_name, item.entity_name, pname, value)
for item in obj_items
for pname, value in zip(
(self.pos_x_parameter, self.pos_y_parameter),
self._spine_db_editor.convert_position(item.pos().x(), item.pos().y()),
)
]
)
for db_map, class_rel_items in db_map_class_rel_items.items():
data = db_map_data.setdefault(db_map, {})
Expand All @@ -485,8 +491,14 @@ def save_positions(self, checked=False):
[(class_name, self.pos_x_parameter), (class_name, self.pos_y_parameter)]
)
data.setdefault("relationship_parameter_values", []).extend(
[(class_name, item.object_name_list, self.pos_x_parameter, item.pos().x()) for item in rel_items]
+ [(class_name, item.object_name_list, self.pos_y_parameter, item.pos().y()) for item in rel_items]
[
(class_name, item.object_name_list, pname, value)
for item in rel_items
for pname, value in zip(
(self.pos_x_parameter, self.pos_y_parameter),
self._spine_db_editor.convert_position(item.pos().x(), item.pos().y()),
)
]
)
self.db_mngr.import_data(db_map_data)

Expand Down
18 changes: 9 additions & 9 deletions spinetoolbox/spine_db_editor/widgets/graph_view_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,20 +460,16 @@ def _update_graph_data(self):

def _get_object_key(self, db_map_object_id):
db_map, object_id = db_map_object_id
key = self.get_item_name(db_map, "object", object_id)
if not key:
object_ = self.db_mngr.get_item(db_map, "object", object_id)
key = (object_["class_name"], object_["name"])
object_ = self.db_mngr.get_item(db_map, "object", object_id)
key = (object_["class_name"], object_["name"])
if not self.ui.graphicsView.merge_dbs:
key += (db_map.codename,)
return key

def _get_relationship_key(self, db_map_relationship_id):
db_map, relationship_id = db_map_relationship_id
key = self.get_item_name(db_map, "relationship", relationship_id)
if not key:
relationship = self.db_mngr.get_item(db_map, "relationship", relationship_id)
key = (relationship["class_name"], relationship["object_class_name_list"], relationship["object_name_list"])
relationship = self.db_mngr.get_item(db_map, "relationship", relationship_id)
key = (relationship["class_name"], relationship["object_class_name_list"], relationship["object_name_list"])
if not self.ui.graphicsView.merge_dbs:
key += (db_map.codename,)
return key
Expand Down Expand Up @@ -598,6 +594,10 @@ def _make_layout_generator(self):
max_iters=max_iters,
)

@staticmethod
def convert_position(x, y):
return (x, -y)

def _make_new_items(self, x, y):
"""Returns new items for the graph.
Expand All @@ -606,7 +606,7 @@ def _make_new_items(self, x, y):
y (list)
"""
self.object_items = [
ObjectItem(self, x[i], y[i], self.VERTEX_EXTENT, tuple(db_map_object_ids))
ObjectItem(self, *self.convert_position(x[i], y[i]), self.VERTEX_EXTENT, tuple(db_map_object_ids))
for i, db_map_object_ids in enumerate(self.db_map_object_id_sets)
]
offset = len(self.object_items)
Expand Down

0 comments on commit a572700

Please sign in to comment.