From 6ab6803fd35ceff1836f5868bbe0910c2bec5abf Mon Sep 17 00:00:00 2001 From: Vassil Kateliev Date: Tue, 26 Mar 2024 12:57:06 +0200 Subject: [PATCH] Issue #91: [Epic] Undo states and object updates: - Quick temporary fix in pGlyph object [Proxy]; - Fix in Curve [Actions] --- Lib/typerig/proxy/fl/actions/curve.py | 30 +++++++++++++++++++-------- Lib/typerig/proxy/fl/objects/glyph.py | 27 +++++++----------------- 2 files changed, 29 insertions(+), 28 deletions(-) diff --git a/Lib/typerig/proxy/fl/actions/curve.py b/Lib/typerig/proxy/fl/actions/curve.py index 79d8f89..b9e5d62 100644 --- a/Lib/typerig/proxy/fl/actions/curve.py +++ b/Lib/typerig/proxy/fl/actions/curve.py @@ -30,7 +30,7 @@ import typerig.proxy.fl.gui.dialogs as TRDialogs # - Init ------------------------- -__version__ = '2.71' +__version__ = '2.72' active_workspace = pWorkspace() # - Keep compatibility for basestring checks @@ -48,6 +48,7 @@ class TRCurveActionCollector(object): def segment_convert(pMode:int, pLayers:tuple, to_curve:bool=False): # - Get list of glyphs to be processed process_glyphs = getProcessGlyphs(pMode) + undo_msg = 'Convert Segment.' # - Process for glyph in process_glyphs: @@ -82,9 +83,11 @@ def segment_convert(pMode:int, pLayers:tuple, to_curve:bool=False): else: glyph.contours(layer)[cID].nodes()[nID].convertToLine() - glyph.update() - glyph.updateObject(glyph.fl, '{};\tConvert Segment @ {}.'.format(glyph.name, '; '.join(wLayers))) + glyph.update(layer) + # - Finish + output(0, 'TypeRig Curve', undo_msg + '@ {}'.format('; '.join(wLayers))) + fl6.flItems.notifyChangesApplied(undo_msg, [glyph.fl for glyph in process_glyphs], True) active_workspace.getCanvas(True).refreshAll() # - Contour optimization ------------------------------------------------- @@ -93,6 +96,7 @@ def curve_optimize(pMode:int, pLayers:tuple, method_values:tuple): # - Get list of glyphs to be processed process_glyphs = getProcessGlyphs(pMode) method_name, p0_value, p1_value = method_values + undo_msg = 'Optimize curve: {} @ {}.' # - Process for glyph in process_glyphs: @@ -117,9 +121,11 @@ def curve_optimize(pMode:int, pLayers:tuple, method_values:tuple): elif method_name == 'proportional': work_segment.eqProportionalHandles((p0_value, p1_value)) - glyph.update() - glyph.updateObject(glyph.fl, '{};\tOptimize curve: {} @ {}.'.format(glyph.name, method_name.title(), '; '.join(wLayers))) + glyph.update(layer) + # - Finish it + output(0, 'TypeRig Curve', undo_msg.format(method_name.title(), '; '.join(wLayers))) + fl6.flItems.notifyChangesApplied(undo_msg, [glyph.fl for glyph in process_glyphs], True) active_workspace.getCanvas(True).refreshAll() @staticmethod @@ -165,6 +171,7 @@ def curve_optimize_by_dict(pMode:int, pLayers:tuple, method_name:basestring, met '''Layer specific curve optimization, best used together with copy''' # - Get list of glyphs to be processed process_glyphs = getProcessGlyphs(pMode) + undo_msg = 'Optimize curve' # - Process for glyph in process_glyphs: @@ -189,9 +196,11 @@ def curve_optimize_by_dict(pMode:int, pLayers:tuple, method_name:basestring, met tension = method_dict[layer] if not swap_values else (method_dict[layer][1], method_dict[layer][0]) work_segment.eqProportionalHandles(tension) - glyph.update() - glyph.updateObject(glyph.fl, '{};\tOptimize curve: {} @ {}.'.format(glyph.name, method_name.title(), '; '.join(wLayers))) + glyph.update(layer) + # - Finish it + output(0, 'TypeRig Curve', undo_msg + ': {} @ {}.'.format(method_name.title(), '; '.join(wLayers))) + fl6.flItems.notifyChangesApplied(undo_msg, [glyph.fl for glyph in process_glyphs], True) active_workspace.getCanvas(True).refreshAll() @staticmethod @@ -204,6 +213,7 @@ def hobby_tension_push(pMode:int, pLayers:tuple): for glyph in process_glyphs: wLayers = glyph._prepareLayers(pLayers) active_layer_selection = glyph.selectedNodes(None, filterOn=True) + undo_msg = 'Copy curve tension' for layer in wLayers: node_skip_list = [] @@ -228,9 +238,11 @@ def hobby_tension_push(pMode:int, pLayers:tuple): base_tension = base_segment.curve.solve_hobby_curvature() work_segment.eqHobbySpline(base_tension) - glyph.update() - glyph.updateObject(glyph.fl, '{};\tCopy curve tension @ {}.'.format(glyph.name, '; '.join(wLayers))) + glyph.update(layer) + # - Finish it + output(0, 'TypeRig Curve', undo_msg + ' @ {}.'.format('; '.join(wLayers))) + fl6.flItems.notifyChangesApplied(undo_msg, [glyph.fl for glyph in process_glyphs], True) active_workspace.getCanvas(True).refreshAll() diff --git a/Lib/typerig/proxy/fl/objects/glyph.py b/Lib/typerig/proxy/fl/objects/glyph.py index c35e042..f209958 100644 --- a/Lib/typerig/proxy/fl/objects/glyph.py +++ b/Lib/typerig/proxy/fl/objects/glyph.py @@ -32,7 +32,7 @@ from typerig.proxy.fl.objects.string import diactiricalMarks # - Init ------------------------------------------- -__version__ = '0.31.4' +__version__ = '0.31.5' # - Keep compatibility for basestring checks try: @@ -748,9 +748,9 @@ def reportLayerComp(self, strong=False): return [(layerA.name, layerB.name, layerA.isCompatible(layerB, strong)) for layerA, layerB in combinations(self.layers(), 2)] # - Update ---------------------------------------------- - def update(self): + def update(self, layer): '''Updates the glyph and sends notification to the editor. ''' - for contour in self.contours(): + for contour in self.contours(layer): contour.changed() def updateObject(self, flObject, undoMessage='TypeRig', verbose=True): @@ -758,27 +758,16 @@ def updateObject(self, flObject, undoMessage='TypeRig', verbose=True): Args: flObject (flGlyph, flLayer, flShape, flNode, flContour): Object to be update and set undo state undoMessage (string): Message to be added in undo/history list.''' - - # - New from 6774 on - for contour in self.contours(): - contour.changed() - + + # !!! QuickFix: Issue #91 Undo... should be removed after all code is fixed + for layer in self.masters(): + self.update(layer.name) + # - General way ---- pre 6774 worked fine! fl6.flItems.notifyChangesApplied(undoMessage[:20], flObject, True) if verbose: print('DONE:\t{}'.format(undoMessage)) - #fl6.flItems.notifyPackageContentUpdated(self.fl.fgPackage.id) fl6.UpdateAll() - - '''# - Type specific way - # -- Covers flGlyph, flLayer, flShape - if isinstance(flObject, fl6.flGlyph) or isinstance(flObject, fl6.flLayer) or isinstance(flObject, fl6.flShape): - fl6.flItems.notifyChangesApplied(undoMessage, flObject, True) - - # -- Covers flNode, flContour, (flShape.shapeData) - elif isinstance(flObject, fl6.flContour) or isinstance(flObject, fl6.flNode): - fl6.flItems.notifyChangesApplied(undoMessage, flObject.shapeData) - ''' # - Glyph Selection ----------------------------------------------- def selectedNodesOnCanvas(self, filterOn=False):