Skip to content

Commit

Permalink
Fix empty collection removing, use blendcfg boolean for switching sol…
Browse files Browse the repository at this point in the history
…der-related processing instead of global variable
  • Loading branch information
marcelnowicki committed Jan 28, 2025
1 parent 7562175 commit 1df5a1b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
16 changes: 10 additions & 6 deletions src/gerber2blend/modules/board.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ def make_board() -> bpy.types.Object:
0,
]
) # type: ignore
if config.solder:

if config.blendcfg["EFFECTS"]["SOLDER"]:
solder_top = prepare_solder(OUT_F_SOLDER, config.pcbscale_vtracer)
if solder_top is not None:
solder_top.location[0] -= pcb.dimensions[0] / 2
Expand All @@ -128,19 +129,23 @@ def make_board() -> bpy.types.Object:
solder_top.select_set(True)
if not bpy.context.selected_objects:
# both top and bottom solder are empty
config.solder = False
config.blendcfg["EFFECTS"]["SOLDER"] = False
else:
bpy.ops.object.join()
solder = bpy.context.selected_objects[0] # type:ignore
solder.name = "Solder"
bpy.ops.object.shade_smooth()
bpy.ops.object.select_all(action="DESELECT")
clear_and_set_solder_material(solder)
cu.remove_collection(f"{OUT_F_SOLDER}.svg")
cu.remove_collection(f"{OUT_B_SOLDER}.svg")

for obj in bpy.context.scene.objects:
cu.apply_all_transform_obj(obj)

cu.remove_collection(f"{OUT_F_SOLDER}")
cu.remove_collection(f"{OUT_B_SOLDER}")
cu.remove_collection(f"{OUT_F_SOLDER}_fixer.svg")
cu.remove_collection(f"{OUT_B_SOLDER}_fixer.svg")

# move pcb and holes to center; move holes below Z
pcb.location -= offset_to_center # type:ignore
if pth:
Expand Down Expand Up @@ -180,7 +185,6 @@ def make_board() -> bpy.types.Object:
cu.remove_collection(f"{GBR_EDGE_CUTS}.svg")
cu.remove_collection(f"{GBR_PTH}.svg")
cu.remove_collection(f"{GBR_NPTH}.svg")

# extrude board
extrude_mesh(pcb, layer_thickness[0])
cu.recalc_normals(pcb)
Expand Down Expand Up @@ -214,7 +218,7 @@ def make_board() -> bpy.types.Object:

process_materials(board_col, all_list)

if config.solder:
if config.blendcfg["EFFECTS"]["SOLDER"]:
cu.link_obj_to_collection(solder, board_col)

# board measurements
Expand Down
3 changes: 0 additions & 3 deletions src/gerber2blend/modules/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
g2bhickness: float = 0.0
pcbscale_gerbv: float = 0.0
pcbscale_vtracer: float = 0.0
solder: bool = True
board_created = False


Expand All @@ -75,7 +74,6 @@ def init_global(arguments: argparse.Namespace) -> int:
global blendcfg
global args
global g2b_dir_path
global solder

prj_path = getcwd() + "/"
g2b_dir_path = path.dirname(__file__) + "/.."
Expand All @@ -95,7 +93,6 @@ def init_global(arguments: argparse.Namespace) -> int:

configure_paths(arguments)
configure_constants(arguments)
solder = blendcfg["EFFECTS"].get("SOLDER", True)

args = arguments
return 1
Expand Down
2 changes: 1 addition & 1 deletion src/gerber2blend/modules/gerbv_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ def prepare_silks(in_file: str, mask: str = "", out_file: str = "") -> None:

def prepare_solder() -> None:
"""Prepare PNG with Solder placements."""
if config.solder:
if config.blendcfg["EFFECTS"]["SOLDER"]:
logger.info("Generate PNGs with solder placement")
prepare_solder_side(GBR_F_CU, GBR_F_MASK, GBR_F_PASTE, OUT_F_SOLDER)
prepare_solder_side(GBR_B_CU, GBR_B_MASK, GBR_B_PASTE, OUT_B_SOLDER)
Expand Down

0 comments on commit 1df5a1b

Please sign in to comment.