Skip to content

Commit

Permalink
Volumes: create and remove volume class instances
Browse files Browse the repository at this point in the history
See #1765.
  • Loading branch information
aschampion authored and tomka committed Oct 16, 2018
1 parent 3f4d117 commit 3649b99
Showing 1 changed file with 39 additions and 7 deletions.
46 changes: 39 additions & 7 deletions django/applications/catmaid/control/volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,33 @@ def save(self):
raise ValueError("Can't create new volume without mesh")

cursor.execute("""
INSERT INTO catmaid_volume (user_id, project_id, editor_id, name,
comment, creation_time, edition_time, geometry)
VALUES (%(uid)s, %(pid)s, %(uid)s, %(t)s, %(c)s, now(), now(), """ +
surface + """)
RETURNING id;""", params)
WITH v AS (
INSERT INTO catmaid_volume (user_id, project_id, editor_id, name,
comment, creation_time, edition_time, geometry)
VALUES (%(uid)s, %(pid)s, %(uid)s, %(t)s, %(c)s, now(), now(), """ +
surface + """)
RETURNING user_id, project_id, id
), ci AS (
INSERT INTO class_instance (user_id, project_id, name, class_id)
SELECT %(uid)s, project_id, %(t)s, id
FROM class
WHERE project_id = %(pid)s AND class_name = 'volume'
RETURNING id
), r AS (
SELECT id FROM relation
WHERE project_id = %(pid)s AND relation_name = 'model_of'
)
INSERT INTO volume_class_instance
(user_id, project_id, relation_id, volume_id, class_instance_id)
SELECT
v.user_id,
v.project_id,
r.id,
v.id,
ci.id
FROM v, ci, r
RETURNING volume_id
""", params)

return cursor.fetchone()[0]

Expand Down Expand Up @@ -405,7 +427,17 @@ def remove_volume(request, project_id, volume_id):
raise Exception("You don't have permissions to delete this volume")

cursor.execute("""
DELETE FROM catmaid_volume WHERE id=%s
WITH v AS (
DELETE FROM catmaid_volume WHERE id=%s RETURNING id
), vci AS (
DELETE FROM volume_class_instance
USING v
WHERE volume_id = v.id
RETURNING class_instance_id
)
DELETE FROM class_instance
USING vci
WHERE id = vci.class_instance_id;
""", (volume_id,))

return Response({
Expand Down Expand Up @@ -586,7 +618,7 @@ def import_volumes(request, project_id):
name, extension = os.path.splitext(filename)
if extension.lower() == ".stl":
stl_str = uploadedfile.read().decode('utf-8')

try:
vertices, triangles = _stl_ascii_to_indexed_triangles(stl_str)
except InvalidSTLError as e:
Expand Down

0 comments on commit 3649b99

Please sign in to comment.