cleanup prints

This commit is contained in:
jrkb 2025-05-26 06:55:29 +02:00
parent 8f3d58aad0
commit e14251523b
2 changed files with 6 additions and 124 deletions

View file

@ -1805,7 +1805,6 @@ def link_text_object_with_new_text_properties(text_object, scene = None):
def detect_text():
lock_depsgraph_updates(auto_unlock_s=-1)
print("DETECT TEXT:: begin")
scene = bpy.context.scene
abc3d_data = scene.abc3d_data
required_keys = [
@ -1817,48 +1816,24 @@ def detect_text():
]
objects = scene.objects
for o in objects:
print(f" {o.name=}")
valid = True
for key in required_keys:
if butils.get_key(key) not in o:
# print(f" key {butils.get_key(key)} not there")
valid = False
break
if not valid:
continue
print(" object may be valid textobject")
if o[butils.get_key("type")] == "textobject":
print(" {o.name=} a textobject")
print(f" {type(o)=} {o.name=}")
current_text_id = int(o[butils.get_key("text_id")])
text_properties = butils.get_text_properties(current_text_id)
if (
text_properties is not None
and text_properties.text_object == o
):
print(" {o.name=} seems fine")
# all good
pass
# t = abc3d_data.available_texts[text_id]
# a = test_availability(o[butils.get_key("font_name")],
# o[butils.get_key("face_name")],
# o[butils.get_key("text")])
# butils.transfer_text_object_to_text_properties(o, t)
else:
butils.link_text_object_with_new_text_properties(o, scene)
# print(" {o.name=} is a duplicate")
# text_id = butils.find_free_text_id()
# t = abc3d_data.available_texts.add()
# t["text_id"] = text_id
# print(f" found free {text_id=}")
# print(" preparing text")
# butils.prepare_text(o[butils.get_key("font_name")],
# o[butils.get_key("face_name")],
# o[butils.get_key("text")])
# print(" prepared text, transferring text object")
# t.text_object = o
# butils.transfer_text_object_to_text_properties(o, t)
# print(" {o.name=} transerred text object")
print("DETECT TEXT:: end")
unlock_depsgraph_updates()
@ -1935,7 +1910,6 @@ import time
@persistent
def on_depsgraph_update(scene, depsgraph):
print("DEPSGRAPH:: BEGIN")
if not bpy.context.mode.startswith("EDIT") and not are_depsgraph_updates_locked():
for u in depsgraph.updates:
if (
@ -1943,31 +1917,19 @@ def on_depsgraph_update(scene, depsgraph):
and butils.get_key("type") in u.id.keys()
and u.id[butils.get_key("type")] == "textobject"
):
print("DEPSGRAPH:: we have a textobject")
text_id = u.id[butils.get_key("text_id")]
if u.is_updated_geometry:
print(" updated geometry is true")
print(f" is {len(scene.abc3d_data.available_texts)} bigger than {text_id=} is true?")
# butils.detect_texts()
# if u.is_updated_geometry:
text_properties = butils.get_text_properties(text_id)
if text_properties is not None:
print(" YES")
print(f" is ? {text_properties.text_object.name=} is {u.id.name=}")
if text_properties.text_object == u.id.original:
print(" yes by id")
# nothing to do
pass
else:
# must be duplicate
link_text_object_with_new_text_properties(u.id.original, scene)
print(" no by id")
else:
# must be new thing
print(" NO, LINK TO NEW TEXTOBJECT")
link_text_object_with_new_text_properties(u.id.original, scene)
print(" NO")
print("DEPSGRAPH:: done textobject")
if are_depsgraph_updates_locked():
print(" L O C K E D")
print("DEPSGRAPH:: done")
def register():

View file

@ -871,22 +871,17 @@ def compare_text_properties_to_text_object(text_properties, o):
text_object_property = o[object_key] if object_key in o else False
if text_property != text_object_property:
if key in keys_trigger_regeneration:
print(f"{key}: REGENERATE {text_property=} {text_object_property}")
return COMPARE_TEXT_OBJECT_REGENERATE
elif key in ["translation", "orientation"]:
if (
text_property[0] != text_object_property[0] or
text_property[1] != text_object_property[1] or
text_property[2] != text_object_property[2]):
print(f"{key}: DIFFER {text_property=} {text_object_property}")
return COMPARE_TEXT_OBJECT_DIFFER
else:
print(f"{key}: SAME {text_property.xyz=} {text_object_property.to_list()}")
# else same
else:
print(f"{key}: DIFFER {text_property=} {text_object_property}")
return COMPARE_TEXT_OBJECT_DIFFER
else:
print(f"{key}: SAME {text_property=} {text_object_property}")
# else same
return COMPARE_TEXT_OBJECT_SAME
@ -965,9 +960,6 @@ def duplicate(obj, data=True, actions=True, add_to_collection=True, collection=N
return obj_copy
def transfer_text_object_to_text_properties(text_object, text_properties, id_from_text_properties=True):
print("TRANSFER:: BEGIN")
print(f" {text_properties['text_id']=}")
print(f" {type(text_object)=}")
possible_brother_text_id = text_object[get_key("text_id")] if get_key("text_id") in text_object else ""
for key in text_object_keys:
if key in ignore_keys_in_text_object_comparison:
@ -975,17 +967,12 @@ def transfer_text_object_to_text_properties(text_object, text_properties, id_fro
object_key = get_key(key)
if id_from_text_properties and key == "text_id":
text_object[object_key] = text_properties["text_id"]
print(f" {object_key} <= {key}")
else:
text_object_property = text_object[object_key] if object_key in text_object else False
if text_object_property is not False:
print(f" {object_key} => {key}")
text_properties[key] = text_object_property
print(f" {dict(text_properties)=}")
print(f" {text_properties['offset']=}")
if len(text_object.children) == 0:
print("ccccccccccccccccccccccccccccccccc ccccc ccccc c c c c ccould be duplicate?")
if possible_brother_text_id != text_properties["text_id"] and possible_brother_text_id != "":
possible_brother_properties = get_text_properties(possible_brother_text_id)
possible_brother_object = possible_brother_properties.text_object
@ -1021,7 +1008,6 @@ def transfer_text_object_to_text_properties(text_object, text_properties, id_fro
glyph_objects_with_indices.append(glyph_object)
glyph_objects_with_indices.sort(key=lambda g: g[get_key("glyph_index")])
print(f" {glyph_objects_with_indices=}")
text = ""
for g in glyph_objects_with_indices:
text += g[get_key("glyph_id")]
@ -1029,7 +1015,6 @@ def transfer_text_object_to_text_properties(text_object, text_properties, id_fro
if len(text) > 0:
if text == text_properties.text:
is_good_text = True
print(f"{text=} is a good text because it is the same")
else:
availability = Font.test_availability(text_properties.font_name, text_properties.face_name, text_properties.text)
AVAILABILITY = Font.test_availability(text_properties.font_name, text_properties.face_name, text_properties.text.swapcase())
@ -1039,17 +1024,8 @@ def transfer_text_object_to_text_properties(text_object, text_properties, id_fro
for c in AVAILABILITY["missing"]:
t_text = t_text.replace(c, "")
if len(t_text) == len(text):
print(f"{text=} is a good text because it is the same considering what is possible")
is_good_text = True
if is_good_text:
print(" GOOD TEXT")
# for glyph_index, glyph_object in enumerate(glyph_objects_with_indices):
# print(f"{glyph_index}: {glyph_object}")
# if glyph_index == glyph_object[get_key("glyph_index")]:
# print("yeey glyph_index matches")
# else:
# print("nooo glyph_idex macthes not")
# found_reconstructable_glyphs = True
text_properties.actual_text = text
text_properties.glyphs.clear()
prepare_text(text_properties.font_name, text_properties.face_name, text)
@ -1069,7 +1045,6 @@ def transfer_text_object_to_text_properties(text_object, text_properties, id_fro
for c in glyph_object.children:
if c.name.startswith(f"{glyph_id}_mesh"):
inner_node = c
print(f"found inner node {inner_node.name=} for {glyph_id=}")
if inner_node is None:
fail_after_all = True
pass
@ -1077,41 +1052,12 @@ def transfer_text_object_to_text_properties(text_object, text_properties, id_fro
if not fail_after_all:
found_reconstructable_glyphs = True
# gp = text_properties.glyphs[i]
# if gp["glyph_id"] == g["glyph_id"] or gp["glyph_id"] == g["glyph_id"].swapcase():
# if "alternate" in g:
# gp["alternate"] = g["alternate"]
# for key in glyph_object_keys:
# if key in ignore_keys_in_glyph_object_comparison:
# continue
# object_key = get_key(key)
# if object_key in g:
# gp[key] = g[object_key]
# else:
# text_properties.glyphs.clear()
# # for g in found_glyphs_with_indices:
# # i = g["glyph_index"]
# # gp = text_properties.glyphs.add()
# # if gp["glyph_id"] == g["glyph_id"] or gp["glyph_id"] == g["glyph_id"].swapcase():
# # if "alternate" in g:
# # gp["alternate"] = g["alternate"]
# # for key in glyph_object_keys:
# # if key in ignore_keys_in_glyph_object_comparison:
# # continue
# # object_key = get_key(key)
# # if object_key in g:
# # gp[key] = g[object_key]
if not found_reconstructable_glyphs:
print("KILL THE GLYPHS")
text_properties.actual_text = ""
text_properties.glyphs.clear()
unfortunate_children = text_object.children
print("KILL THE CHILDREN")
completely_delete_objects(unfortunate_children)
def kill_children():
print("KILL THE CHILDREN")
completely_delete_objects(unfortunate_children)
run_in_main_thread(kill_children)
@ -1120,8 +1066,6 @@ def transfer_text_object_to_text_properties(text_object, text_properties, id_fro
face_name = text_properties["face_name"]
text_properties.font = f"{font_name} {face_name}"
print("TRANSFER:: END")
def link_text_object_with_new_text_properties(text_object, scene=None):
if scene is None:
@ -1130,12 +1074,9 @@ def link_text_object_with_new_text_properties(text_object, scene=None):
text_properties = scene.abc3d_data.available_texts.add()
text_properties["text_id"] = text_id
# text_object[get_key("text_id")] = text_id
print(f" found free {text_id=}")
print(" preparing text")
prepare_text(text_object[get_key("font_name")],
text_object[get_key("face_name")],
text_object[get_key("text")])
print(" prepared text, transferring text object")
text_properties.text_object = text_object
transfer_text_object_to_text_properties(text_object, text_properties)
@ -1145,9 +1086,7 @@ def test_finding():
abc3d_data = scene.abc3d_data
text_id = find_free_text_id()
t = abc3d_data.available_texts.add()
print(type(t))
t["text_id"] = text_id
print(t["text_id"])
o = bpy.context.active_object
transfer_text_object_to_text_properties(o, t)
@ -1189,46 +1128,34 @@ def transfer_glyph_object_to_glyph_properties(glyph_object, glyph_properties):
glyph_properties[key] = glyph_object[get_key(key)]
glyph_properties["text_id"] = glyph_object[get_key("text_id")]
import inspect
def would_regenerate(text_properties):
print("REGENERATE?")
predicted_text = predict_actual_text(text_properties)
if text_properties.actual_text != predicted_text:
print(inspect.currentframe().f_lineno)
return True
if len(text_properties.glyphs) == 0:
print(inspect.currentframe().f_lineno)
return True
for i, g in enumerate(text_properties.glyphs):
if not hasattr(g.glyph_object, "type"):
print(inspect.currentframe().f_lineno)
return True
elif g.glyph_object.type != "EMPTY":
print(inspect.currentframe().f_lineno)
return True
# check if perhaps one glyph was deleted
elif g.glyph_object is None:
print(inspect.currentframe().f_lineno)
return True
elif g.glyph_object.parent is None:
print(inspect.currentframe().f_lineno)
return True
elif g.glyph_object.parent.users_collection != g.glyph_object.users_collection:
print(inspect.currentframe().f_lineno)
return True
elif len(text_properties.text) > i and g.glyph_id != text_properties.text[i]:
print(inspect.currentframe().f_lineno)
return True
elif len(text_properties.text) > i and (
g.glyph_object[f"{utils.prefix()}_font_name"] != text_properties.font_name
or g.glyph_object[f"{utils.prefix()}_face_name"]
!= text_properties.face_name
):
print(inspect.currentframe().f_lineno)
return True
print("NOT REGENERATE")
return False
@ -1270,9 +1197,6 @@ def parent_to_curve(o, c):
def set_text_on_curve(text_properties, reset_timeout_s=0.1, reset_depsgraph_n=4, can_regenerate=False):
# for i in range (0, 42):
# print("WATCH OUT, WE DO NOT SET THE TEXT ATM")
# return False
"""set_text_on_curve
An earlier reset cancels the other.
@ -1310,13 +1234,9 @@ def set_text_on_curve(text_properties, reset_timeout_s=0.1, reset_depsgraph_n=4,
# mom.data.use_path = True
regenerate = can_regenerate and would_regenerate(text_properties)
if regenerate:
print("RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRREGENERATE")
# if we regenerate.... delete objects
if regenerate and text_properties.get("glyphs"):
for g in text_properties.glyphs:
print(dict(g))
glyph_objects = [g["glyph_object"] for g in text_properties["glyphs"]]
completely_delete_objects(glyph_objects, True)
text_properties.glyphs.clear()