Implement fully undo/redo with checks

While these actions are short in the backend--taking about 0.01 seconds to run--the Blender UI lags a lot leading to 2-3 second pauses because of the "refresh_brick_viewer" function being slow. This should be investigated.
This commit is contained in:
Trashman247
2023-06-27 13:21:44 -07:00
parent 36d0e33958
commit 2b52ab930c
5 changed files with 40 additions and 5 deletions
@@ -33,6 +33,8 @@ classes = (
operator.RewindBrickClass,
operator.ViewBrickClass,
operator.ViewBrickItem,
operator.UndoBrick,
operator.RedoBrick,
operator.SerializeBrick,
prop.Brick,
prop.BIMBrickProperties,
@@ -190,6 +190,20 @@ class RemoveBrick(bpy.types.Operator, Operator):
brick_uri=props.bricks[props.active_brick_index].uri,
)
class UndoBrick(bpy.types.Operator, Operator):
bl_idname = "bim.undo_brick"
bl_label = "Undo Brick"
def _execute(self, context):
core.undo_brick(tool.Brick)
class RedoBrick(bpy.types.Operator, Operator):
bl_idname = "bim.redo_brick"
bl_label = "Redo Brick"
def _execute(self, context):
core.redo_brick(tool.Brick)
class SerializeBrick(bpy.types.Operator, Operator):
bl_idname = "bim.serialize_brick"
bl_label = "Serialize Brick"
@@ -58,6 +58,10 @@ class BIM_PT_brickschema(Panel):
row.operator("bim.add_brick_feed", text="", icon="PLUGIN")
row.operator("bim.remove_brick", text="", icon="X")
row = self.layout.row(align=True)
row.operator("bim.undo_brick", icon="LOOP_BACK")
row.operator("bim.redo_brick", icon="LOOP_FORWARDS")
row = self.layout.row(align=True)
row.operator("bim.serialize_brick")
+8
View File
@@ -110,5 +110,13 @@ def remove_brick(ifc, brick, library=None, brick_uri=None):
brick.remove_brick(brick_uri)
brick.run_refresh_brick_viewer()
def undo_brick(brick):
brick.undo_brick()
brick.run_refresh_brick_viewer()
def redo_brick(brick):
brick.redo_brick()
brick.run_refresh_brick_viewer()
def serialize_brick(brick, file_name="BlenderBIMSerializeTest.ttl"):
brick.serialize_brick(file_name)
+12 -5
View File
@@ -282,9 +282,10 @@ class Brick(blenderbim.core.tool.Brick):
@classmethod
def remove_brick(cls, brick_uri):
with BrickStore.graph.new_changeset("PROJECT") as cs:
for triple in BrickStore.graph.triples((URIRef(brick_uri), None, None)):
cs.remove(triple)
if(BrickStore.graph.triples((URIRef(brick_uri), None, None))):
with BrickStore.graph.new_changeset("PROJECT") as cs:
for triple in BrickStore.graph.triples((URIRef(brick_uri), None, None)):
cs.remove(triple)
@classmethod
def run_assign_brick_reference(cls, element=None, library=None, brick_uri=None):
@@ -312,11 +313,17 @@ class Brick(blenderbim.core.tool.Brick):
@classmethod
def undo_brick(cls):
BrickStore.graph.undo()
if(len(BrickStore.graph.versions()) > 1):
BrickStore.graph.undo()
@classmethod
def redo_brick(cls):
BrickStore.graph.redo()
with BrickStore.graph.conn() as conn:
redo_record = conn.execute(
"SELECT * from redos " "ORDER BY timestamp ASC LIMIT 1"
).fetchone()
if redo_record is not None:
BrickStore.graph.redo()
@classmethod
def serialize_brick(cls, file_name):