152 lines
7.1 KiB
Python
152 lines
7.1 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""
|
|
Created on Mon May 1 03:35:45 2023
|
|
|
|
@author: Edward Middleton-Smith
|
|
|
|
Braille 3D Model Product Creation
|
|
"""
|
|
|
|
# CLASSES
|
|
# ATTRIBUTE DECLARATION
|
|
# METHODS
|
|
# FUNCTION
|
|
# ARGUMENTS
|
|
# ARGUMENT VALIDATION
|
|
# ATTRIBUTE + VARIABLE INSTANTIATION
|
|
# METHODS
|
|
# RETURNS
|
|
|
|
# NORMAL METHODS
|
|
# FUNCTION
|
|
# ARGUMENTS
|
|
# ARGUMENT VALIDATION
|
|
# VARIABLE INSTANTIATION
|
|
# METHODS
|
|
# RETURNS
|
|
|
|
|
|
import openpyscad as ops
|
|
import system_commands as sc
|
|
import argument_validation as av
|
|
from translate_msg_2_braille import product, gen_braille_inputs_4_openscad
|
|
from translate_braille_2_scad import scrabble_dimensions, export_colour_theme, input_colour_themes, gen_openscad_braille, gen_path_braille_scrabble, input_product_size
|
|
from typing import Optional
|
|
|
|
def gen_product_permutations(my_product, szs_product, sz_perms = True, sz_index = 2):
|
|
# FUNCTION
|
|
# generate all colour / size permutations of product
|
|
# ARGUMENTS
|
|
# product my_product
|
|
# list[scrabble_dimensions] szs_product - different size profiles for products
|
|
# optional bool szs_perms
|
|
# optional int sz_index
|
|
# ARGUMENT VALIDATION
|
|
_m = 'gen_product_permutations'
|
|
av.val_type(my_product, "<class 'translate_msg_2_braille.product'>", 'my_product', _m)
|
|
av.val_list(szs_product, 'szs_product', _m, "<class 'translate_braille_2_scad.scrabble_dimensions'>", 1)
|
|
av.full_val_bool(sz_perms, 'sz_perms', _m)
|
|
# VARIABLE INSTANTIATION
|
|
mymsgs = [] # [msgin]
|
|
myszs = [] # [szs_scrabble[5]]
|
|
# METHODS
|
|
if not sz_perms:
|
|
my_size = input_product_size(szs_product, sz_index)
|
|
# create list of permutations of size profiles + letters
|
|
for j in range(len(szs_product) if sz_perms else 1):
|
|
for i in range(26 if my_product.name == 'Scrabble Alphabet of Tiles' else 1):
|
|
mymsgs.append(chr(65 + i) if my_product.name == 'Scrabble Character Tile' else my_product.msg)
|
|
myszs.append(szs_product[j] if sz_perms else my_size)
|
|
# RETURNS
|
|
return mymsgs, myszs
|
|
|
|
def gen_3d_models(braille_dict, myproduct, mymsgs, myszs, line_length, path_folder, path_cmd, mystyle, col_themes):
|
|
# FUNCTION
|
|
# create 3D models - SCAD, STL, PNG - from product input
|
|
# ARGUMENTS
|
|
# list[braille_trans] braille_dict
|
|
# product myproduct
|
|
# list[str] mymsgs
|
|
# list[scrabble_dimensions] myszs
|
|
# int line_length
|
|
# str path_folder
|
|
# style mystyle
|
|
# list [export_colour_themes] col_themes
|
|
# ARGUMENT VALIDATION
|
|
_m = 'gen_3d_models'
|
|
av.val_type(braille_dict, "<class 'pandas.core.frame.DataFrame'>", 'braille_dict', _m)
|
|
av.val_type(myproduct, "<class 'translate_msg_2_braille.product'>", 'myproduct', _m)
|
|
av.val_list(mymsgs, 'mymsgs', _m, "<class 'str'>", 1)
|
|
av.val_list(myszs, 'myszs', _m, "<class 'translate_braille_2_scad.scrabble_dimensions'>", 1) #:
|
|
# raise ValueError(av.error_msg_str(_m, 'myszs', myszs, "<class 'scrabble_dimensions'>"))
|
|
av.val_int(line_length, 'line_length', _m, 1)
|
|
av.val_str(path_folder, 'path_folder', _m)
|
|
av.val_str(path_cmd, 'path_cmd', _m, 1)
|
|
# av.val_int(show_braille, 'show_braille', _m)
|
|
# av.val_int(show_let, 'show_let', _m)
|
|
# av.val_int(show_num, 'show_num', _m)
|
|
# av.val_type(show_braille, "<enum 'elem_visibility'>", 'show_braille', _m)
|
|
# av.val_type(show_let, "<enum 'elem_visibility'>", 'show_let', _m)
|
|
# av.val_type(show_num, "<enum 'elem_visibility'>", 'show_num', _m)
|
|
av.val_type(mystyle, "<class 'translate_braille_2_scad.style'>", 'mystyle', _m)
|
|
av.val_list(col_themes, 'col_themes', _m, "<class 'translate_braille_2_scad.export_colour_theme'>", 1)
|
|
# VARIABLE INSTANTIATION
|
|
# METHODS
|
|
for col_y in range(len(col_themes)):
|
|
for msg_x in range(len(mymsgs)):
|
|
msg_x_str = mymsgs[msg_x]
|
|
cum, letters, numbers, braille, n_keys, n_rows = gen_braille_inputs_4_openscad(msg_x_str, line_length, braille_dict)
|
|
path_png, path_scad, path_stl = gen_openscad_braille(cum, letters, numbers, braille, n_keys, min(line_length, n_keys), n_rows, myszs[msg_x], mystyle, col_themes[col_y], msg_x_str, path_folder + myproduct.filename, quality = 100)
|
|
# sc.render_openscad(path_scad, path_stl, path_cmd)
|
|
# sc.render_openscad(path_scad, path_png, path_cmd)
|
|
# # RETURNS
|
|
# return col_themes
|
|
|
|
def gen_snippet_assembly(dx, dy, len_line, col_themes, myszs, my_product, path_folder, path_cmd, my_style): #, szs_product
|
|
# FUNCTION
|
|
# create png exports of openscad assembly of series of permutations of openscad components
|
|
# ARGUMENTS
|
|
# int dx - spacing along x
|
|
# int dy - spacing along y
|
|
# int len_line - number of components on row (along x)
|
|
# list[export_colour_theme] col_themes
|
|
# list[scrabble_dimensions] myszs
|
|
# translate_msg_2_braille.product my_product
|
|
# str path_folder
|
|
# str path_cmd
|
|
# style my_style
|
|
# # list[scrabble_dimensions] szs_product
|
|
# ARGUMENT VALIDATION
|
|
_m = 'gen_snippet_assembly'
|
|
av.val_int(dx, 'dx', _m)
|
|
av.val_int(dy, 'dy', _m)
|
|
av.val_int(len_line, 'len_line', _m, 1)
|
|
av.val_list(col_themes, 'col_themes', _m, "<class 'translate_braille_2_scad.export_colour_theme'>")
|
|
# av.val_list(szs_product, 'szs_product', _m, "<class 'translate_braille_2_scad.scrabble_dimensions'>", 1)
|
|
av.val_list(myszs, 'myszs', _m, "<class 'translate_braille_2_scad.scrabble_dimensions'>", 1)
|
|
av.val_type(my_product, "<class 'translate_msg_2_braille.product'>", 'my_product', _m)
|
|
av.val_str(path_folder, 'path_folder', _m)
|
|
av.val_str(path_cmd, 'path_cmd', _m, 1)
|
|
av.val_type(my_style, "<class 'translate_braille_2_scad.style'>", 'my_style', _m)
|
|
# VARIABLE INSTANTIATION
|
|
# mystyles = ['__l_0n'] # ['_0n', '_0l_0n', '_0b_0n', '__l_0n']
|
|
n_style = 1 # 3
|
|
d_pcs = [dx, dy]
|
|
# METHODS
|
|
for sz_i in range(len(myszs)):
|
|
ass_braille = ops.Union()
|
|
for let_i in range(1): # 26):
|
|
col_i = 0 # let_i % n_col
|
|
style_i = 0 # let_i % n_style
|
|
# mypath = gen_path_braille_scrabble(szs_scrabble[sz_i], let_i, col_themes[col_i], 'scad')
|
|
mypath = gen_path_braille_scrabble(myszs[sz_i], col_themes[col_i], my_style, path_folder + my_product.filename, 'scad')
|
|
# mypath = f"C:\\Users\\edwar\\OneDrive\\Documents\\Programming\\Python Scripts\\Braille_Scrabble_{szs_scrabble[sz_i].name}_{Chr(let_i + 65)}_{col_themes[col_i].name}"
|
|
ass_braille.append(ops.Scad(mypath).rotate([0, 180 * let_i, 0]).translate([4 * (let_i % 2), 0, -5 * (let_i % 2)]).translate([d_pcs[0] * myszs[sz_i].dp * (let_i % len_line), d_pcs[1] * myszs[sz_i].dp * (let_i // len_line), 0])) # , convexity = 3) .translate([d_pcs * (let_i % len_line), d_pcs * (let_i // len_line), 0])
|
|
# RETURNS
|
|
path_scad = gen_path_braille_scrabble(myszs[0], col_themes[col_i], my_style, path_folder + 'assy', 'scad')
|
|
path_stl = gen_path_braille_scrabble(myszs[0], col_themes[col_i], my_style, path_folder + 'assy', 'stl')
|
|
path_png = gen_path_braille_scrabble(myszs[0], col_themes[col_i], my_style, path_folder + 'assy', 'png')
|
|
ass_braille.write(path_scad) # , with_print=True
|
|
print(f"writing SCAD to {path_scad}")
|
|
# render_openscad(path_scad, path_stl)
|
|
sc.render_openscad(path_scad, path_png, path_cmd) |