Skip to content

Commit

Permalink
Issue #91: [Epic] Undo states and object updates:
Browse files Browse the repository at this point in the history
- Quick temporary fix in pGlyph object [Proxy];
- Fix in Curve [Actions]
  • Loading branch information
kateliev committed Mar 26, 2024
1 parent 4777013 commit 6ab6803
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 28 deletions.
30 changes: 21 additions & 9 deletions Lib/typerig/proxy/fl/actions/curve.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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 -------------------------------------------------
Expand All @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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 = []
Expand All @@ -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()


27 changes: 8 additions & 19 deletions Lib/typerig/proxy/fl/objects/glyph.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -748,37 +748,26 @@ 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):
'''Updates a flObject sends notification to the editor as well as undo/history item.
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):
Expand Down

0 comments on commit 6ab6803

Please sign in to comment.