diff --git a/bin/cnc25d_example_generator.py b/bin/cnc25d_example_generator.py index 1c2d68e..b2971a3 100755 --- a/bin/cnc25d_example_generator.py +++ b/bin/cnc25d_example_generator.py @@ -33,6 +33,8 @@ import os, re, sys import subprocess +import six +from six.moves import input ############################################################################## # Checking FreeCAD installation @@ -76,11 +78,11 @@ freecad_verion_major = int(freecad_verion[0]) freecad_verion_minor = int(freecad_verion[1]) if((freecad_verion_major==0)and(freecad_verion_minor<13)): - print("ERR056: Error, Your FreeCAD version is too old! You have {:d}.{:d} and 0.13 or newer is needed.".format(freecad_verion_major, freecad_verion_minor)) + six.print_(("ERR056: Error, Your FreeCAD version is too old! You have {:d}.{:d} and 0.13 or newer is needed.".format(freecad_verion_major, freecad_verion_minor))) print("Please, install the latest FreeCAD version on your system and re-run this script.") sys.exit(1) #info -print("The FreeCAD version {:d}.{:d} is installed on your system.".format(freecad_verion_major, freecad_verion_minor)) +six.print_(("The FreeCAD version {:d}.{:d} is installed on your system.".format(freecad_verion_major, freecad_verion_minor))) ### check if the FreeCAD Library can be imported @@ -4014,8 +4016,8 @@ def sub_canvas_graphics(ai_rotation_direction, ai_angle_position): ceg_example_list_sorted_keys = sorted(ceg_example_list.keys()) print("\nThis executable helps you to generate the following cnc25d script examples in the current directory:") for l_example in ceg_example_list_sorted_keys: - print(" + {:s}".format(l_example)) -user_choice=raw_input("Do you want to generate all these upper files in the current directory? [yes/No] ") + six.print_((" + {:s}".format(l_example))) +user_choice=input("Do you want to generate all these upper files in the current directory? [yes/No] ") if((user_choice=='yes')or(user_choice=='y')): for l_example in ceg_example_list_sorted_keys: fh_output = open(l_example, 'w') @@ -4025,14 +4027,14 @@ def sub_canvas_graphics(ai_rotation_direction, ai_angle_position): else: print("Choose which cnc25d script example you want to generate in the current directory:") for l_example in ceg_example_list_sorted_keys: - print("cnc25d script example : {:s}".format(l_example)) - user_choice=raw_input("Do you want to generate the file {:s} in the current directory? [yes/No] ".format(l_example)) + six.print_(("cnc25d script example : {:s}".format(l_example))) + user_choice=input("Do you want to generate the file {:s} in the current directory? [yes/No] ".format(l_example)) if((user_choice=='yes')or(user_choice=='y')): fh_output = open(l_example, 'w') fh_output.write(ceg_example_list[l_example]) fh_output.close() - print(ceg_instructions.format(l_example, l_example, l_example)) + six.print_((ceg_instructions.format(l_example, l_example, l_example))) else: - print("The script example {:s} has not been created.".format(l_example)) + six.print_(("The script example {:s} has not been created.".format(l_example))) diff --git a/bin/cnc25d_example_generator_src.py b/bin/cnc25d_example_generator_src.py index 4028807..5a11502 100755 --- a/bin/cnc25d_example_generator_src.py +++ b/bin/cnc25d_example_generator_src.py @@ -33,6 +33,8 @@ import os, re, sys import subprocess +import six +from six.moves import input ############################################################################## # Checking FreeCAD installation @@ -76,11 +78,11 @@ freecad_verion_major = int(freecad_verion[0]) freecad_verion_minor = int(freecad_verion[1]) if((freecad_verion_major==0)and(freecad_verion_minor<13)): - print("ERR056: Error, Your FreeCAD version is too old! You have {:d}.{:d} and 0.13 or newer is needed.".format(freecad_verion_major, freecad_verion_minor)) + six.print_(("ERR056: Error, Your FreeCAD version is too old! You have {:d}.{:d} and 0.13 or newer is needed.".format(freecad_verion_major, freecad_verion_minor))) print("Please, install the latest FreeCAD version on your system and re-run this script.") sys.exit(1) #info -print("The FreeCAD version {:d}.{:d} is installed on your system.".format(freecad_verion_major, freecad_verion_minor)) +six.print_(("The FreeCAD version {:d}.{:d} is installed on your system.".format(freecad_verion_major, freecad_verion_minor))) ### check if the FreeCAD Library can be imported @@ -317,8 +319,8 @@ ceg_example_list_sorted_keys = sorted(ceg_example_list.keys()) print("\nThis executable helps you to generate the following cnc25d script examples in the current directory:") for l_example in ceg_example_list_sorted_keys: - print(" + {:s}".format(l_example)) -user_choice=raw_input("Do you want to generate all these upper files in the current directory? [yes/No] ") + six.print_((" + {:s}".format(l_example))) +user_choice=input("Do you want to generate all these upper files in the current directory? [yes/No] ") if((user_choice=='yes')or(user_choice=='y')): for l_example in ceg_example_list_sorted_keys: fh_output = open(l_example, 'w') @@ -328,14 +330,14 @@ else: print("Choose which cnc25d script example you want to generate in the current directory:") for l_example in ceg_example_list_sorted_keys: - print("cnc25d script example : {:s}".format(l_example)) - user_choice=raw_input("Do you want to generate the file {:s} in the current directory? [yes/No] ".format(l_example)) + six.print_(("cnc25d script example : {:s}".format(l_example))) + user_choice=input("Do you want to generate the file {:s} in the current directory? [yes/No] ".format(l_example)) if((user_choice=='yes')or(user_choice=='y')): fh_output = open(l_example, 'w') fh_output.write(ceg_example_list[l_example]) fh_output.close() - print(ceg_instructions.format(l_example, l_example, l_example)) + six.print_((ceg_instructions.format(l_example, l_example, l_example))) else: - print("The script example {:s} has not been created.".format(l_example)) + six.print_(("The script example {:s} has not been created.".format(l_example))) diff --git a/cnc25d/angles.py b/cnc25d/angles.py index 43a3f2b..832347b 100644 --- a/cnc25d/angles.py +++ b/cnc25d/angles.py @@ -30,6 +30,7 @@ ################################################################ import math +import six ################################################################ # functions @@ -53,7 +54,7 @@ def roll_pitch_to_pan_tilt(ai_a1, ai_a2): if(abs(sin_A)<1+radian_epsilon): sin_A = math.copysign(1, sin_A) else: - print("ERR053: Internal Error, sin_A {:0.3f}".format(sin_A)) + six.print_(("ERR053: Internal Error, sin_A {:0.3f}".format(sin_A))) sys.exit(2) A = math.asin(sin_A) b1 = b1_sign*math.pi/2 - A diff --git a/cnc25d/axle_lid.py b/cnc25d/axle_lid.py index 7cb8653..d1b2d58 100644 --- a/cnc25d/axle_lid.py +++ b/cnc25d/axle_lid.py @@ -29,7 +29,8 @@ # header for Python / FreeCAD compatibility ################################################################ -import cnc25d_api +from . import cnc25d_api +import six cnc25d_api.importing_freecad() #print("FreeCAD.Version:", FreeCAD.Version()) @@ -52,7 +53,7 @@ #import svgwrite #from dxfwrite import DXFEngine # cnc25d -import gearring +from . import gearring ################################################################ # inheritance from gearring @@ -225,19 +226,19 @@ def axle_lid_constraint_check(c): # print("ERR141: Error, cnc_router_bit_radius {:0.3f} is bigger than axle_hole_radius {:0.3f}".format(c['cnc_router_bit_radius'], c['axle_hole_radius'])) # sys.exit(2) if(c['axle_hole_radius']>c['central_radius']-radian_epsilon): - print("ERR144: Error, axle_hole_radius {:0.3f} is bigger than central_radius {:0.3f}".format(c['axle_hole_radius'], c['central_radius'])) + six.print_(("ERR144: Error, axle_hole_radius {:0.3f} is bigger than central_radius {:0.3f}".format(c['axle_hole_radius'], c['central_radius']))) sys.exit(2) if(c['central_radius']>c['clearance_radius']-radian_epsilon): - print("ERR147: Error, central_radius {:0.3f} is bigger than clearance_radius {:0.3f}".format(c['central_radius'], c['clearance_radius'])) + six.print_(("ERR147: Error, central_radius {:0.3f} is bigger than clearance_radius {:0.3f}".format(c['central_radius'], c['clearance_radius']))) sys.exit(2) if(c['clearance_radius']>c['holder_radius']-radian_epsilon): - print("ERR151: Error, clearance_radius {:0.3f} is bigger than the holder_radius {:0.3f}".format(c['clearance_radius'], c['holder_radius'])) + six.print_(("ERR151: Error, clearance_radius {:0.3f} is bigger than the holder_radius {:0.3f}".format(c['clearance_radius'], c['holder_radius']))) sys.exit(2) if(c['annulus_holder_axle_hole_radius']>c['clearance_radius']): - print("ERR159: Error, annulus_holder_axle_hole_radius {:0.3f} is bigger than clearance_radius {:0.3f}".format(c['annulus_holder_axle_hole_radius'], c['clearance_radius'])) + six.print_(("ERR159: Error, annulus_holder_axle_hole_radius {:0.3f} is bigger than clearance_radius {:0.3f}".format(c['annulus_holder_axle_hole_radius'], c['clearance_radius']))) sys.exit(2) if(c['holder_crenel_number']<4): - print("ERR154: Error, holder_crenel_number {:d} is smaller than 4".format(c['holder_crenel_number'])) + six.print_(("ERR154: Error, holder_crenel_number {:d} is smaller than 4".format(c['holder_crenel_number']))) sys.exit(2) c['middle_crenel_1'] = 0 c['middle_crenel_2'] = int(c['holder_crenel_number']/2) @@ -267,22 +268,22 @@ def axle_lid_constraint_check(c): c['leg_hole_distance'] = 2*(2*c['leg_hole_radius'] + c['leg_hole_length']) if(c['leg_type'] != 'none'): if((c['leg_type'] != 'rear') and (c['leg_type'] != 'side')): - print("ERR536: Error, leg_type {:s} set to an unknow value. Possible values: 'none', 'rear' or 'side'".format(c['leg_type'])) + six.print_(("ERR536: Error, leg_type {:s} set to an unknow value. Possible values: 'none', 'rear' or 'side'".format(c['leg_type']))) sys.exit(2) if(c['leg_length']<=0): - print("ERR539: Error, leg_length {:0.3f} must be strictly positive".format(c['leg_length'])) + six.print_(("ERR539: Error, leg_length {:0.3f} must be strictly positive".format(c['leg_length']))) sys.exit(2) if(c['toe_length']0): if(c['output_axle_B_crenel_radius'](c['output_axle_B_external_radius']-c['output_axle_B_crenel_radius'])): - print("ERR463: Error, output_axle_B_crenel_position_radius {:0.3f} is too big compare to output_axle_B_external_radius {:0.3f} and output_axle_B_crenel_radius {:0.3f}".format(c['output_axle_B_crenel_position_radius'], c['output_axle_B_external_radius'], c['output_axle_B_crenel_radius'])) + six.print_(("ERR463: Error, output_axle_B_crenel_position_radius {:0.3f} is too big compare to output_axle_B_external_radius {:0.3f} and output_axle_B_crenel_radius {:0.3f}".format(c['output_axle_B_crenel_position_radius'], c['output_axle_B_external_radius'], c['output_axle_B_crenel_radius']))) sys.exit(2) ## calculation of the angle (DCE) ABC = (c['middle_crenel_2'] - c['middle_crenel_1'] - 1) * c['crenel_portion_angle'] / 2.0 - c['holder_crenel_half_angle'] @@ -495,7 +496,7 @@ def axle_lid_2d_construction(c): AC1 = math.sqrt(AB**2 + BC**2 - 2*AB*BC*math.cos(ABC1)) cos_ACB1 = ((AC1**2+BC**2-AB**2)/(2*AC1*BC)) if((cos_ACB11-radian_epsilon)): - print("ERR474: Error, cos_ACB1 {:0.3f} is out of the range 0..1".format(cos_ACB1)) + six.print_(("ERR474: Error, cos_ACB1 {:0.3f} is out of the range 0..1".format(cos_ACB1))) sys.exit(2) ACB1 = math.acos(cos_ACB1) DC = c['output_axle_B_external_radius'] @@ -539,10 +540,10 @@ def axle_lid_2d_construction(c): # external_axle_B_half_angle external_axle_B_half_angle = math.atan(float(input_axle_B_external_radius)/c['holder_radius']) if(first_angle>c['output_axle_B_angle']-external_axle_B_half_angle): - print("ERR500: Error, first_angle {:0.3f} too big compare to output_axle_B_angle {:0.3f} and external_axle_B_half_angle {:0.3f}".format(first_angle, c['output_axle_B_angle'], external_axle_B_half_angle)) + six.print_(("ERR500: Error, first_angle {:0.3f} too big compare to output_axle_B_angle {:0.3f} and external_axle_B_half_angle {:0.3f}".format(first_angle, c['output_axle_B_angle'], external_axle_B_half_angle))) sys.exit(2) if(last_angle c['bagel_axle_external_radius']-c['axle_hole_radius']-radian_epsilon): - print("ERR183: Error: axle_hole_position_radius {:0.3f} is too big compare to bagel_axle_external_radius {:0.3f} and axle_hole_radius {:0.3f}".format(c['axle_hole_position_radius'], c['bagel_axle_external_radius'], c['axle_hole_radius'])) + six.print_(("ERR183: Error: axle_hole_position_radius {:0.3f} is too big compare to bagel_axle_external_radius {:0.3f} and axle_hole_radius {:0.3f}".format(c['axle_hole_position_radius'], c['bagel_axle_external_radius'], c['axle_hole_radius']))) sys.exit(2) # axle_hole_angle # external_bagel_thickness if(c['external_bagel_thickness']c['bagel_axle_radius']/2.0): - print("ERR212: Error, bagel_extra_cut_thickness {:0.3f} is too big compare to bagel_axle_radius {:0.3f}".format(c['bagel_extra_cut_thickness'], c['bagel_axle_radius'])) + six.print_(("ERR212: Error, bagel_extra_cut_thickness {:0.3f} is too big compare to bagel_axle_radius {:0.3f}".format(c['bagel_extra_cut_thickness'], c['bagel_axle_radius']))) sys.exit(2) return(c) diff --git a/cnc25d/bare_design.py b/cnc25d/bare_design.py index 2870a16..1d888db 100644 --- a/cnc25d/bare_design.py +++ b/cnc25d/bare_design.py @@ -34,9 +34,10 @@ from datetime import datetime import os # -import outline_backends -import design_help -import design_output +from . import outline_backends +from . import design_help +from . import design_output +import six ################################################################ # bare_design class @@ -188,7 +189,7 @@ def apply_constraint(self, constraint): new_contraint_value = 0 for k in constraint.keys(): if(not k in rc.keys()): - print("ERR177: Error, contraint {:k} is not part of the design".format(k)) + six.print_(("ERR177: Error, contraint {:k} is not part of the design".format(k))) sys.exit(2) if(c[k] != constraint[k]): new_contraint_value += 1 @@ -215,7 +216,7 @@ def apply_constraint(self, constraint): def apply_external_constraint(self, constraint): """ set the dictionary constraint to the design without generating error on unknow constraint """ - key_list = self.reference_constraint.viewkeys() & constraint.viewkeys() + key_list = self.reference_constraint & constraint c = dict([ (k, constraint[k]) for k in key_list ]) #print("dbg207: {:s} apply_external_constraint: constraint_nb: {:d}".format(self.design_name, len(c))) #print("dbg170: c:", c) @@ -307,7 +308,7 @@ def get_A_figure(self, figure_id=""): figure_id = self.A_figures.keys()[0] #print("dbg194: figure_id:", figure_id) if(not figure_id in self.A_figures.keys()): - print("ERR156: Error, figure_id {:s} is not in the figure list [{:s}]".format(figure_id, ' '.join(self.A_figures.keys()))) + six.print_(("ERR156: Error, figure_id {:s} is not in the figure list [{:s}]".format(figure_id, ' '.join(self.A_figures.keys())))) sys.exit(2) r_fig = self.A_figures[figure_id] return(r_fig) @@ -333,20 +334,20 @@ def get_display_2d_figure_list(self): r_list = figs for f in r_list: if(not f in self.A_figures.keys()): - print("ERR304: Error, f {:s} is not an existing 2d-figures {:s}".format(f, ' '.join(self.A_figures.keys()))) + six.print_(("ERR304: Error, f {:s} is not an existing 2d-figures {:s}".format(f, ' '.join(self.A_figures.keys())))) sys.exit(2) return(r_list) def outline_display(self): """ display in one or several Tk windows the design outline figures """ - print("{:s}".format(self.get_info())) + six.print_(("{:s}".format(self.get_info()))) fig_ids = self.get_display_2d_figure_list() for f in fig_ids: fig = self.A_figures[f] d_info = "display_{:s}".format(f) #print("dbg218: fig:", fig) - print("{:s}".format(d_info)) + six.print_(("{:s}".format(d_info))) outline_backends.figure_simple_display(design_output.cnc_cut_figure(fig, d_info), design_output.ideal_figure(fig, d_info), d_info) def apply_3d_constructor(self): @@ -395,7 +396,7 @@ def get_fc_obj_3dconf(self, assembly_name=""): if(assembly_name==""): assembly_name = self.assembly_configurations.keys()[0] # set the first 3d-assembly-configuration per default if(not assembly_name in self.assembly_configurations.keys()): - print("ERR187: Error, the assembly_name {:s} is not in the possible 3d-assembly-configuration".format(assembly_name)) + six.print_(("ERR187: Error, the assembly_name {:s} is not in the possible 3d-assembly-configuration".format(assembly_name))) sys.exit(2) #print("dbg245: self.assembly_configurations:", self.assembly_configurations) #print("dbg246: assembly_name:", assembly_name) @@ -411,7 +412,7 @@ def get_fc_obj_function(self, function_id=""): if(function_id==""): function_id = self.freecad_function_pts.keys()[0] # set the first 3d-freecad_function_pts per default if(not function_id in self.freecad_function_pts.keys()): - print("ERR370: Error, the function_id {:s} is not in the possible 3d-freecad_function_pts".format(function_id)) + six.print_(("ERR370: Error, the function_id {:s} is not in the possible 3d-freecad_function_pts".format(function_id))) sys.exit(2) r_fc_obj = self.freecad_function_pts[function_id](self.constraint) # execute the function that generate a freecad object return(r_fc_obj) @@ -424,7 +425,7 @@ def write_info_txt(self, output_file_basename): design_help.mkdir_p(l_output_dir) # info_txt_filename = "{:s}_info.txt".format(output_file_basename) - print("Generate the text info file {:s}".format(info_txt_filename)) + six.print_(("Generate the text info file {:s}".format(info_txt_filename))) ofh = open(info_txt_filename, 'w') ofh.write("{:s} generated by Cnc25D on {:s}\n\n".format(info_txt_filename, datetime.now().isoformat())) ofh.write(self.get_info()) @@ -443,7 +444,7 @@ def get_write_2d_figure_list(self): r_list = figs for f in r_list: if(not f in self.A_figures.keys()): - print("ERR291: Error, f {:s} is not an existing 2d-figures {:s}".format(f, ' '.join(self.A_figures.keys()))) + six.print_(("ERR291: Error, f {:s} is not an existing 2d-figures {:s}".format(f, ' '.join(self.A_figures.keys())))) sys.exit(2) return(r_list) @@ -478,7 +479,7 @@ def get_write_3d_figure_list(self): r_list = figs for f in r_list: if(not f in self.A_figures.keys()): - print("ERR380: Error, f {:s} is not an existing 2d-figures {:s}".format(f, ' '.join(self.A_figures.keys()))) + six.print_(("ERR380: Error, f {:s} is not an existing 2d-figures {:s}".format(f, ' '.join(self.A_figures.keys())))) sys.exit(2) return(r_list) @@ -504,7 +505,7 @@ def get_write_3d_conf_list(self): r_list = confs for f in r_list: if(not f in self.assembly_configurations.keys()): - print("ERR406: Error, f {:s} is not an existing 3d-assembly-configurations {:s}".format(f, ' '.join(self.assembly_configurations.keys()))) + six.print_(("ERR406: Error, f {:s} is not an existing 3d-assembly-configurations {:s}".format(f, ' '.join(self.assembly_configurations.keys())))) sys.exit(2) return(r_list) @@ -514,7 +515,7 @@ def write_assembly_brep(self, output_file_basename, ai_brep=True, ai_stl=False): """ confs = self.get_write_3d_conf_list() for a in confs: - print("write_assembly_brep: {:s}".format(a)) + six.print_(("write_assembly_brep: {:s}".format(a))) # (ai_3d_conf, ai_output_filename, ai_brep=True, ai_stl=False, ai_slice_xyz=[]) design_output.generate_3d_assembly_output_file(self.complete_assembly_conf(self.assembly_configurations[a]), "{:s}_{:s}".format(output_file_basename, a), ai_brep=ai_brep, ai_stl=ai_stl, ai_slice_xyz=self.slice3d_configurations[a]) @@ -532,7 +533,7 @@ def get_write_3d_freecad_list(self): r_list = l for f in r_list: if(not f in self.freecad_function_pts.keys()): - print("ERR460: Error, f {:s} is not an existing 3d-freecad_function_pts {:s}".format(f, ' '.join(self.freecad_function_pts.keys()))) + six.print_(("ERR460: Error, f {:s} is not an existing 3d-freecad_function_pts {:s}".format(f, ' '.join(self.freecad_function_pts.keys())))) sys.exit(2) return(r_list) @@ -549,14 +550,14 @@ def run_simulation(self, sim_id=''): """ run the simulation sim_id """ if(len(self.simulation_2d_pts)==0): - print("ERR268: Error, no simulation function is provided. Can't run 2d-simulate {:s}".format(sim_id)) + six.print_(("ERR268: Error, no simulation function is provided. Can't run 2d-simulate {:s}".format(sim_id))) sys.exit(2) if(sim_id==''): sim_id = self.simulation_2d_pts.keys()[0] if(not sim_id in self.simulation_2d_pts.keys()): - print("ERR382: Error, the simulation id {:s} does not exist in the list {:s}".format(sim_id, ' '.join(self.simulation_2d_pts.keys()))) + six.print_(("ERR382: Error, the simulation id {:s} does not exist in the list {:s}".format(sim_id, ' '.join(self.simulation_2d_pts.keys())))) sys.exit(2) - print("SIMULATION: {:s} runs simulation: {:s}".format(self.design_name, sim_id)) + six.print_(("SIMULATION: {:s} runs simulation: {:s}".format(self.design_name, sim_id))) #self.simulation_2d_pts[sim_id](self.constraint) # writing correct but too compact for my eyes ;) f_simulation = self.simulation_2d_pts[sim_id] f_simulation(self.constraint) @@ -568,70 +569,70 @@ def view_design_configuration(self): # 2D-figures (figs, height) = self.apply_2d_constructor() fig_ids = figs.keys() - print("{:s} 2D-figures:".format(self.design_name)) + six.print_(("{:s} 2D-figures:".format(self.design_name))) if(len(fig_ids)==0): print("No 2D-figures") else: for i in range(len(fig_ids)): - print("{:02d} : {:s}".format(i, fig_ids[i])) + six.print_(("{:02d} : {:s}".format(i, fig_ids[i]))) # 2D-simulations sim_ids = self.simulation_2d_pts.keys() - print("{:s} 2D-simulations:".format(self.design_name)) + six.print_(("{:s} 2D-simulations:".format(self.design_name))) if(len(sim_ids)==0): print("No 2D-simulation") else: for i in range(len(sim_ids)): - print("{:02d} : {:s}".format(i, sim_ids[i])) + six.print_(("{:02d} : {:s}".format(i, sim_ids[i]))) # assembly_3d_configurations if(self.f_3d_constructor==None): print("No assembly_3dconf") else: self.apply_3d_constructor() assembly_ids = self.assembly_configurations.keys() - print("{:s} assembly_3dconf:".format(self.design_name)) + six.print_(("{:s} assembly_3dconf:".format(self.design_name))) for i in range(len(assembly_ids)): - print("{:02d} : {:s}".format(i, assembly_ids[i])) + six.print_(("{:02d} : {:s}".format(i, assembly_ids[i]))) # assembly_3d_freecad_configurations if(self.f_3d_freecad_constructor==None): print("No freecad_3dconf") else: self.apply_3d_freecad_constructor() fc_ids = self.freecad_function_pts.keys() - print("{:s} freecad_function_pts:".format(self.design_name)) + six.print_(("{:s} freecad_function_pts:".format(self.design_name))) for i in range(len(fc_ids)): - print("{:02d} : {:s}".format(i, fc_ids[i])) + six.print_(("{:02d} : {:s}".format(i, fc_ids[i]))) # display_2d_figure_list - print("{:s} display_2d_figure_list:".format(self.design_name)) + six.print_(("{:s} display_2d_figure_list:".format(self.design_name))) figs = self.get_display_2d_figure_list() for i in range(len(figs)): - print("{:02d} : {:s}".format(i, figs[i])) + six.print_(("{:02d} : {:s}".format(i, figs[i]))) # default_simulation - print("{:s} default_simulation: {:s}".format(self.design_name, self.default_simulation)) + six.print_(("{:s} default_simulation: {:s}".format(self.design_name, self.default_simulation))) # file_2d_figure_file_list - print("{:s} svg-dxf-file_2d_figure_list:".format(self.design_name)) + six.print_(("{:s} svg-dxf-file_2d_figure_list:".format(self.design_name))) figs = self.get_write_2d_figure_list() for i in range(len(figs)): - print("{:02d} : {:s}".format(i, figs[i])) + six.print_(("{:02d} : {:s}".format(i, figs[i]))) # file_3d_figure_file_list - print("{:s} brep-file_3d_figure_list:".format(self.design_name)) + six.print_(("{:s} brep-file_3d_figure_list:".format(self.design_name))) figs = self.get_write_3d_figure_list() for i in range(len(figs)): - print("{:02d} : {:s}".format(i, figs[i])) + six.print_(("{:02d} : {:s}".format(i, figs[i]))) # file_3d_conf_file_list - print("{:s} brep-file_3d_conf_list:".format(self.design_name)) + six.print_(("{:s} brep-file_3d_conf_list:".format(self.design_name))) confs = self.get_write_3d_conf_list() for i in range(len(confs)): - print("{:02d} : {:s}".format(i, confs[i])) + six.print_(("{:02d} : {:s}".format(i, confs[i]))) # file_3d_freecad_file_list - print("{:s} brep-file_3d_freecad_list:".format(self.design_name)) + six.print_(("{:s} brep-file_3d_freecad_list:".format(self.design_name))) fc_l = self.get_write_3d_freecad_list() for i in range(len(fc_l)): - print("{:02d} : {:s}".format(i, fc_l[i])) + six.print_(("{:02d} : {:s}".format(i, fc_l[i]))) # self-test-list test_ids = [] for i in range(len(self.self_tests)): test_ids.append(self.self_tests[i][0]) - print("design_self-test_list: {:s}".format(', '.join(test_ids))) + six.print_(("design_self-test_list: {:s}".format(', '.join(test_ids)))) # return (not yet used) return(fig_ids) @@ -717,7 +718,7 @@ def apply_cli_with_output_options(self, cli_str=""): r_cli = 1 if(oo_args.sw_return_type!=''): if(self.f_return_type==None): - print("ERR277: Error, no return_type function is provided. Can't apply return_type {:s}".format(oo_args.sw_return_type)) + six.print_(("ERR277: Error, no return_type function is provided. Can't apply return_type {:s}".format(oo_args.sw_return_type))) sys.exit(2) r_cli = self.f_return_type(oo_args.sw_return_type, self.constraint) return(r_cli) @@ -737,20 +738,20 @@ def run_self_test(self, test_id=''): test_list.extend(test_ids) else: if(not test_id in test_ids): - print("ERR541: Error, test_id {:s} is not in the test-list {:s}".format(test_id, ', '.join(test_ids))) + six.print_(("ERR541: Error, test_id {:s} is not in the test-list {:s}".format(test_id, ', '.join(test_ids)))) sys.exit(2) test_list.append(test_id) - print("\nInfo: test_list: {:s}\n".format(', '.join(test_list))) + six.print_(("\nInfo: test_list: {:s}\n".format(', '.join(test_list)))) for i in range(len(test_list)): tn=-1 for j in range(len(test_ids)): if(test_ids[j]==test_list[i]): tn=j if(tn==-1): - print("ERR562: the test {:s} has not been found".format(test_list[i])) + six.print_(("ERR562: the test {:s} has not been found".format(test_list[i]))) sys.exit(2) else: - print("{:2d} test case: '{:s}'\nwith switch: {:s}".format(tn+1, self.self_tests[tn][0], self.self_tests[tn][1])) + six.print_(("{:2d} test case: '{:s}'\nwith switch: {:s}".format(tn+1, self.self_tests[tn][0], self.self_tests[tn][1]))) self.apply_constraint_default_value() self.apply_cli_with_output_options(self.self_tests[tn][1]) return(1) @@ -763,10 +764,10 @@ def dump_constraint_file(self, snippet_filename): sys.exit(2) constraint_dict = vars(self.parser.parse_args([])) py_txt = "" - for (k,v) in constraint_dict.iteritems(): + for (k,v) in six.iteritems(constraint_dict): #py_txt += "\t{:30s}\t= {:s}\n".format(k, str(v)) py_txt += "c[\'{:s}\']\t= {:s}\n".format(k, str(v)) - print("Generate the python snippet file {:s}".format(snippet_filename)) + six.print_(("Generate the python snippet file {:s}".format(snippet_filename))) ofh = open(snippet_filename, 'w') ofh.write("# {:s} generated by cnc25d.bare_design for the design example {:s}\n\n".format(snippet_filename, self.design_name)) ofh.write(py_txt) @@ -807,9 +808,9 @@ def cli(self, cli_str=""): # import for testing bare_design #import cnc25d_api # cannot import cnc25d_api because cnc25d_api import bare_design -import importing_freecad +from . import importing_freecad importing_freecad.importing_freecad() -import cnc_outline +from . import cnc_outline #print("FreeCAD.Version:", FreeCAD.Version()) #FreeCAD.Console.PrintMessage("Hello from PrintMessage!\n") # avoid using this method because it is not printed in the FreeCAD GUI # @@ -847,19 +848,19 @@ def cube_constraint_check(c): c['height'] = c['length'] # check the constraint if(c['width']c['length']*10.0): - print("ERR132: Error, width {:0.3f} is too big compare to length {:0.3f}".format(c['width'], c['length'])) + six.print_(("ERR132: Error, width {:0.3f} is too big compare to length {:0.3f}".format(c['width'], c['length']))) sys.exit(2) if(c['height']c['length']*10.0): - print("ERR138: Error, height {:0.3f} is too big compare to length {:0.3f}".format(c['height'], c['length'])) + six.print_(("ERR138: Error, height {:0.3f} is too big compare to length {:0.3f}".format(c['height'], c['length']))) sys.exit(2) if(c['smooth_radius']>0.4*min(c['length'], c['width'])): - print("ERR182: Error, smooth_radius {:0.3f} is too big compare to length {:0.3f} or width {:0.3f}".format(c['smooth_radius'], c['length'], c['width'])) + six.print_(("ERR182: Error, smooth_radius {:0.3f} is too big compare to length {:0.3f} or width {:0.3f}".format(c['smooth_radius'], c['length'], c['width']))) sys.exit(2) return(c) diff --git a/cnc25d/bell.py b/cnc25d/bell.py index 9347d53..1907e08 100644 --- a/cnc25d/bell.py +++ b/cnc25d/bell.py @@ -29,7 +29,8 @@ # header for Python / FreeCAD compatibility ################################################################ -import cnc25d_api +from . import cnc25d_api +import six cnc25d_api.importing_freecad() #print("FreeCAD.Version:", FreeCAD.Version()) @@ -52,7 +53,7 @@ #import svgwrite #from dxfwrite import DXFEngine # cnc25d -import bell_outline +from . import bell_outline ################################################################ @@ -222,7 +223,7 @@ def bell_constraint_check(c): radian_epsilon = math.pi/1000 # axle_internal_diameter if(c['axle_internal_diameter']c['bell_face_width']/5.0): - print("ERR361: Error, face_thickness {:0.3f} is too big compare to bell_face_width {:0.3f}".format(c['face_thickness'], c['bell_face_width'])) + six.print_(("ERR361: Error, face_thickness {:0.3f} is too big compare to bell_face_width {:0.3f}".format(c['face_thickness'], c['bell_face_width']))) sys.exit(2) # side_thickness if(c['side_thickness']==0.0): c['side_thickness'] = c['face_thickness'] if(c['side_thickness']>c['bell_face_width']/5.0): - print("ERR367: Error, side_thickness {:0.3f} is too big compare to bell_face_width {:0.3f}".format(c['side_thickness'], c['bell_face_width'])) + six.print_(("ERR367: Error, side_thickness {:0.3f} is too big compare to bell_face_width {:0.3f}".format(c['side_thickness'], c['bell_face_width']))) sys.exit(2) # base_thickness if(c['base_thickness']==0.0): @@ -272,198 +273,198 @@ def bell_constraint_check(c): # axle_hole_diameter c['axle_hole_radius'] = c['axle_hole_diameter']/2.0 if(c['axle_hole_radius'] c['axle_external_radius']-c['axle_hole_radius']-radian_epsilon): - print("ERR381: Error: axle_hole_position_radius {:0.3f} is too big compare to axle_external_radius {:0.3f} and axle_hole_radius {:0.3f}".format(c['axle_hole_position_radius'], c['axle_external_radius'], c['axle_hole_radius'])) + six.print_(("ERR381: Error: axle_hole_position_radius {:0.3f} is too big compare to axle_external_radius {:0.3f} and axle_hole_radius {:0.3f}".format(c['axle_hole_position_radius'], c['axle_external_radius'], c['axle_hole_radius']))) sys.exit(2) # axle_hole_angle # leg_spare_width if(c['leg_spare_width'] > (c['bell_face_width']-2*c['axle_external_radius'])/2.0+radian_epsilon): - print("ERR385: Error, leg_spare_width {:0.3f} is too big compare to bell_face_width {:0.3f} and axle_external_radius {:0.3f}".format(c['leg_spare_width'], c['bell_face_width'], c['axle_external_radius'])) + six.print_(("ERR385: Error, leg_spare_width {:0.3f} is too big compare to bell_face_width {:0.3f} and axle_external_radius {:0.3f}".format(c['leg_spare_width'], c['bell_face_width'], c['axle_external_radius']))) sys.exit(2) # leg_smoothing_radius if(c['leg_smoothing_radius']c['leg_length']): - print("ERR392: Error, leg_smoothing_radius {:0.3f} must be bigger than leg_length {:0.3f}".format(c['leg_smoothing_radius'], c['leg_length'])) + six.print_(("ERR392: Error, leg_smoothing_radius {:0.3f} must be bigger than leg_length {:0.3f}".format(c['leg_smoothing_radius'], c['leg_length']))) sys.exit(2) # motor_hole_diameter c['motor_hole_radius'] = c['motor_hole_diameter']/2.0 if(c['motor_hole_radius']>0.0): # motor_hole_x_distance if(c['motor_hole_x_distance']<2*c['motor_hole_radius']+radian_epsilon): - print("ERR399: Error, motor_hole_x_distance {:0.3f} is too small compare to motor_hole_radius {:0.3f}".format(c['motor_hole_x_distance'], c['motor_hole_radius'])) + six.print_(("ERR399: Error, motor_hole_x_distance {:0.3f} is too small compare to motor_hole_radius {:0.3f}".format(c['motor_hole_x_distance'], c['motor_hole_radius']))) sys.exit(2) if(c['motor_hole_x_distance']>c['bell_face_width']-2*c['side_thickness']-2*c['motor_hole_radius']-radian_epsilon): - print("ERR402: Error, motor_hole_x_distance {:0.3f} is too big compare to bell_face_width {:0.3f}, side_thickness {:0.3f} and motor_hole_radius {:0.3f}".format(c['motor_hole_x_distance'], c['bell_face_width'], c['side_thickness'], c['motor_hole_radius'])) + six.print_(("ERR402: Error, motor_hole_x_distance {:0.3f} is too big compare to bell_face_width {:0.3f}, side_thickness {:0.3f} and motor_hole_radius {:0.3f}".format(c['motor_hole_x_distance'], c['bell_face_width'], c['side_thickness'], c['motor_hole_radius']))) sys.exit(2) # motor_hole_z_distance if(c['motor_hole_z_distance']<2*c['motor_hole_radius']+radian_epsilon): - print("ERR406: Error, motor_hole_z_distance {:0.3f} is too small compare to motor_hole_radius {:0.3f}".format(c['motor_hole_z_distance'], c['motor_hole_radius'])) + six.print_(("ERR406: Error, motor_hole_z_distance {:0.3f} is too small compare to motor_hole_radius {:0.3f}".format(c['motor_hole_z_distance'], c['motor_hole_radius']))) sys.exit(2) if(c['motor_hole_z_distance']>c['bell_face_height']+c['leg_length']-2*c['motor_hole_radius']-radian_epsilon): - print("ERR409: Error, motor_hole_z_distance {:0.3f} is too big compare to bell_face_height {:0.3f}, leg_length {:0.3f} and motor_hole_radius {:0.3f}".format(c['motor_hole_z_distance'], c['bell_face_height'], c['leg_length'], c['motor_hole_radius'])) + six.print_(("ERR409: Error, motor_hole_z_distance {:0.3f} is too big compare to bell_face_height {:0.3f}, leg_length {:0.3f} and motor_hole_radius {:0.3f}".format(c['motor_hole_z_distance'], c['bell_face_height'], c['leg_length'], c['motor_hole_radius']))) sys.exit(2) # motor_hole_z_position if(c['motor_hole_z_position']c['bell_face_height']+c['leg_length']-c['motor_hole_z_distance']-2*c['motor_hole_radius']-radian_epsilon): - print("ERR416: Error, motor_hole_z_distance {:0.3f} is too big compare to bell_face_height {:0.3f}, leg_length {:0.3f}, motor_hole_z_distance {:0.3f} and motor_hole_radius {:0.3f}".format(c['motor_hole_z_distance'], c['bell_face_height'], c['leg_length'], c['motor_hole_z_distance'], c['motor_hole_radius'])) + six.print_(("ERR416: Error, motor_hole_z_distance {:0.3f} is too big compare to bell_face_height {:0.3f}, leg_length {:0.3f}, motor_hole_z_distance {:0.3f} and motor_hole_radius {:0.3f}".format(c['motor_hole_z_distance'], c['bell_face_height'], c['leg_length'], c['motor_hole_z_distance'], c['motor_hole_radius']))) sys.exit(2) # int_buttress_x_length if(c['int_buttress_x_length']>(c['bell_face_width']-2*c['side_thickness'])/3.0): - print("ERR426: Error, int_buttress_x_length {:0.3f} is too big compare to bell_face_width {:0.3f} and side_thickness {:0.3f}".format(c['int_buttress_x_length'], c['bell_face_width'], c['side_thickness'])) + six.print_(("ERR426: Error, int_buttress_x_length {:0.3f} is too big compare to bell_face_width {:0.3f} and side_thickness {:0.3f}".format(c['int_buttress_x_length'], c['bell_face_width'], c['side_thickness']))) sys.exit(2) if(c['int_buttress_x_length']>0): # int_buttress_z_width if(c['int_buttress_z_width']<3*c['bell_cnc_router_bit_radius']): - print("ERR431: Error, int_buttress_z_width {:0.3f} is too small compare to bell_cnc_router_bit_radius {:0.3f}".format(c['int_buttress_z_width'], c['bell_cnc_router_bit_radius'])) + six.print_(("ERR431: Error, int_buttress_z_width {:0.3f} is too small compare to bell_cnc_router_bit_radius {:0.3f}".format(c['int_buttress_z_width'], c['bell_cnc_router_bit_radius']))) sys.exit(2) if(c['int_buttress_z_width']>c['bell_face_height']/5.0): - print("ERR434: Error, int_buttress_z_width {:0.3f} is too big compare to bell_face_height {:0.3f}".format(c['int_buttress_z_width'], c['bell_face_height'])) + six.print_(("ERR434: Error, int_buttress_z_width {:0.3f} is too big compare to bell_face_height {:0.3f}".format(c['int_buttress_z_width'], c['bell_face_height']))) sys.exit(2) # int_buttress_z_distance if(c['int_buttress_z_distance']c['bell_face_height']-2*c['int_buttress_z_width']-radian_epsilon): - print("ERR441: Error, int_buttress_z_distance {:0.3f} is too big compare to bell_face_height {:0.3f} and int_buttress_z_width {:0.3f}".format(c['int_buttress_z_distance'], c['bell_face_height'], c['int_buttress_z_width'])) + six.print_(("ERR441: Error, int_buttress_z_distance {:0.3f} is too big compare to bell_face_height {:0.3f} and int_buttress_z_width {:0.3f}".format(c['int_buttress_z_distance'], c['bell_face_height'], c['int_buttress_z_width']))) sys.exit(2) # int_buttress_x_position if(c['int_buttress_x_position']>c['bell_face_width']/2.0-c['face_thickness']-c['int_buttress_x_length']): - print("ERR445: Error, int_buttress_x_position {:0.3f} is too big compare to bell_face_width {:0.3f}, face_thickness {:0.3f} and int_buttress_x_length {:0.3f}".format(c['int_buttress_x_position'], c['bell_face_width'], c['face_thickness'], c['int_buttress_x_length'])) + six.print_(("ERR445: Error, int_buttress_x_position {:0.3f} is too big compare to bell_face_width {:0.3f}, face_thickness {:0.3f} and int_buttress_x_length {:0.3f}".format(c['int_buttress_x_position'], c['bell_face_width'], c['face_thickness'], c['int_buttress_x_length']))) sys.exit(2) # int_buttress_z_position if(c['int_buttress_z_position']>c['bell_face_height']-c['int_buttress_z_distance']-c['int_buttress_z_width']-radian_epsilon): - print("ERR448: int_buttress_z_position {:0.3f} is too big compare to bell_face_height {:0.3f}, int_buttress_z_distance {:0.3f} and int_buttress_z_width {:0.3f}".format(c['int_buttress_z_position'], c['bell_face_height'], c['int_buttress_z_distance'], c['int_buttress_z_width'])) + six.print_(("ERR448: int_buttress_z_position {:0.3f} is too big compare to bell_face_height {:0.3f}, int_buttress_z_distance {:0.3f} and int_buttress_z_width {:0.3f}".format(c['int_buttress_z_position'], c['bell_face_height'], c['int_buttress_z_distance'], c['int_buttress_z_width']))) sys.exit(2) # int_buttress_int_corner_length if(c['int_buttress_int_corner_length']>c['int_buttress_x_position']): - print("ERR453: Error, int_buttress_int_corner_length {:0.3f} must be smaller than int_buttress_x_position {:0.3f}".format(c['int_buttress_int_corner_length'], c['int_buttress_x_position'])) + six.print_(("ERR453: Error, int_buttress_int_corner_length {:0.3f} must be smaller than int_buttress_x_position {:0.3f}".format(c['int_buttress_int_corner_length'], c['int_buttress_x_position']))) sys.exit(2) # int_buttress_ext_corner_length if(c['int_buttress_ext_corner_length']>c['bell_face_width']/2.0-c['face_thickness']-c['int_buttress_x_length']-c['int_buttress_x_position']): - print("ERR457: Error, int_buttress_ext_corner_length {:0.3f} is too big comapre to bell_face_width {:0.3f}, face_thickness {:0.3f}, int_buttress_x_length {:0.3f} and int_buttress_x_position {:0.3f}".format(c['int_buttress_ext_corner_length'], c['bell_face_width'], c['face_thickness'], c['int_buttress_x_length'], c['int_buttress_x_position'])) + six.print_(("ERR457: Error, int_buttress_ext_corner_length {:0.3f} is too big comapre to bell_face_width {:0.3f}, face_thickness {:0.3f}, int_buttress_x_length {:0.3f} and int_buttress_x_position {:0.3f}".format(c['int_buttress_ext_corner_length'], c['bell_face_width'], c['face_thickness'], c['int_buttress_x_length'], c['int_buttress_x_position']))) sys.exit(2) # int_buttress_bump_length if(c['int_buttress_bump_length']>c['int_buttress_x_position']+c['int_buttress_x_length']): - print("ERR461: Error, int_buttress_bump_length {:0.3f} is too big compare to int_buttress_x_position {:0.3f} and int_buttress_x_length {:0.3f}".format(c['int_buttress_bump_length'], c['int_buttress_x_position'], c['int_buttress_x_length'])) + six.print_(("ERR461: Error, int_buttress_bump_length {:0.3f} is too big compare to int_buttress_x_position {:0.3f} and int_buttress_x_length {:0.3f}".format(c['int_buttress_bump_length'], c['int_buttress_x_position'], c['int_buttress_x_length']))) sys.exit(2) # int_buttress_arc_height if(abs(c['int_buttress_arc_height'])>c['int_buttress_x_length']): - print("ERR465: Error, int_buttress_arc_height {:0.3f} absolute value must be smaller than int_buttress_x_length {:0.3f}".format(c['int_buttress_arc_height'], c['int_buttress_x_length'])) + six.print_(("ERR465: Error, int_buttress_arc_height {:0.3f} absolute value must be smaller than int_buttress_x_length {:0.3f}".format(c['int_buttress_arc_height'], c['int_buttress_x_length']))) sys.exit(2) # int_buttress_smoothing_radius if(c['int_buttress_smoothing_radius']>c['int_buttress_bump_length']): - print("ERR469: Error, int_buttress_smoothing_radius {:0.3f} must be smaller than int_buttress_bump_length {:0.3f}".format(c['int_buttress_smoothing_radius'], c['int_buttress_bump_length'])) + six.print_(("ERR469: Error, int_buttress_smoothing_radius {:0.3f} must be smaller than int_buttress_bump_length {:0.3f}".format(c['int_buttress_smoothing_radius'], c['int_buttress_bump_length']))) sys.exit(2) # ext_buttress_z_length if(c['ext_buttress_z_length']>c['bell_face_height']/3.0): - print("ERR473: Error, ext_buttress_z_length {:0.3f} is too big compare to bell_face_height {:0.3f}".format(c['ext_buttress_z_length'], c['bell_face_height'])) + six.print_(("ERR473: Error, ext_buttress_z_length {:0.3f} is too big compare to bell_face_height {:0.3f}".format(c['ext_buttress_z_length'], c['bell_face_height']))) sys.exit(2) if(c['ext_buttress_z_length']>0): # ext_buttress_x_width if(c['ext_buttress_x_width']<3*c['bell_cnc_router_bit_radius']): - print("ERR478: Error, ext_buttress_x_width {:0.3f} is too small compare to bell_cnc_router_bit_radius {:0.3f}".format(c['ext_buttress_x_width'], c['bell_cnc_router_bit_radius'])) + six.print_(("ERR478: Error, ext_buttress_x_width {:0.3f} is too small compare to bell_cnc_router_bit_radius {:0.3f}".format(c['ext_buttress_x_width'], c['bell_cnc_router_bit_radius']))) sys.exit(2) if(c['ext_buttress_x_width']>c['bell_face_width']/5.0): - print("ERR481: Error, ext_buttress_x_width {:0.3f} is too big compare to bell_face_width {:0.3f}".format(c['ext_buttress_x_width'], c['bell_face_width'])) + six.print_(("ERR481: Error, ext_buttress_x_width {:0.3f} is too big compare to bell_face_width {:0.3f}".format(c['ext_buttress_x_width'], c['bell_face_width']))) sys.exit(2) # ext_buttress_x_distance if(c['ext_buttress_x_distance']c['bell_face_width']-2*c['ext_buttress_x_width']-2*c['face_thickness']): - print("ERR488: Error, ext_buttress_x_distance {:0.3f} is too big compare to bell_face_width {:0.3f} ext_buttress_x_width {:0.3f} and face_thickness {:0.3f}".format(c['ext_buttress_x_distance'], c['bell_face_width'], c['ext_buttress_x_width'], c['face_thickness'])) + six.print_(("ERR488: Error, ext_buttress_x_distance {:0.3f} is too big compare to bell_face_width {:0.3f} ext_buttress_x_width {:0.3f} and face_thickness {:0.3f}".format(c['ext_buttress_x_distance'], c['bell_face_width'], c['ext_buttress_x_width'], c['face_thickness']))) sys.exit(2) # ext_buttress_z_position if(c['ext_buttress_z_position']>c['bell_face_height']+c['leg_length']-c['ext_buttress_z_length']): - print("ERR490: Error, ext_buttress_z_position {:0.3f} is too big compare to bell_face_height {:0.3f}, leg_length {:0.3f} and ext_buttress_z_length {:0.3f}".format(c['ext_buttress_z_position'], c['bell_face_height'], c['leg_length'], c['ext_buttress_z_length'])) + six.print_(("ERR490: Error, ext_buttress_z_position {:0.3f} is too big compare to bell_face_height {:0.3f}, leg_length {:0.3f} and ext_buttress_z_length {:0.3f}".format(c['ext_buttress_z_position'], c['bell_face_height'], c['leg_length'], c['ext_buttress_z_length']))) sys.exit(2) # ext_buttress_y_length if(c['ext_buttress_y_length']>c['base_radius']-c['bell_face_width']/2.0): - print("ERR499: Error, ext_buttress_y_length {:0.3f} is too big compare to base_radius {:0.3f} and bell_face_width {:0.3f}".format(c['ext_buttress_y_length'], c['base_radius'], c['bell_face_width'])) + six.print_(("ERR499: Error, ext_buttress_y_length {:0.3f} is too big compare to base_radius {:0.3f} and bell_face_width {:0.3f}".format(c['ext_buttress_y_length'], c['base_radius'], c['bell_face_width']))) sys.exit(2) # ext_buttress_y_position if(math.sqrt((c['ext_buttress_x_distance']/2.0+c['ext_buttress_x_width'])**2+(c['bell_face_width']/2.0+c['ext_buttress_y_position']+c['ext_buttress_y_length'])**2)>c['base_radius']): - print("ERR502: Error, ext_buttress_y_position {:0.3f} is too big compare to ext_buttress_x_distance {:0.3f}, ext_buttress_x_width {:0.3f}, bell_face_width {:0.3f}, ext_buttress_y_length {:0.3f} and base_radius {:0.3f}".format(c['ext_buttress_y_position'], c['ext_buttress_x_distance'], c['ext_buttress_x_width'], c['bell_face_width'], c['ext_buttress_y_length'], c['base_radius'])) + six.print_(("ERR502: Error, ext_buttress_y_position {:0.3f} is too big compare to ext_buttress_x_distance {:0.3f}, ext_buttress_x_width {:0.3f}, bell_face_width {:0.3f}, ext_buttress_y_length {:0.3f} and base_radius {:0.3f}".format(c['ext_buttress_y_position'], c['ext_buttress_x_distance'], c['ext_buttress_x_width'], c['bell_face_width'], c['ext_buttress_y_length'], c['base_radius']))) sys.exit(2) # ext_buttress_face_int_corner_length if(c['ext_buttress_face_int_corner_length']>c['ext_buttress_z_position']): - print("ERR507: Error, ext_buttress_face_int_corner_length {:0.3f} must be smaller than ext_buttress_z_position {:0.3f}".format(c['ext_buttress_face_int_corner_length'], c['ext_buttress_z_position'])) + six.print_(("ERR507: Error, ext_buttress_face_int_corner_length {:0.3f} must be smaller than ext_buttress_z_position {:0.3f}".format(c['ext_buttress_face_int_corner_length'], c['ext_buttress_z_position']))) sys.exit(2) # ext_buttress_face_ext_corner_length if(c['ext_buttress_face_ext_corner_length']>c['bell_face_height']+c['leg_length']-c['ext_buttress_z_length']): - print("ext_buttress_face_ext_corner_length {:0.3f} is too big compare to bell_face_height {:0.3f}, leg_length {:0.3f} and ext_buttress_z_length {:0.3f}".format(c['ext_buttress_face_ext_corner_length'], c['bell_face_height'], c['leg_length'], c['ext_buttress_z_length'])) + six.print_(("ext_buttress_face_ext_corner_length {:0.3f} is too big compare to bell_face_height {:0.3f}, leg_length {:0.3f} and ext_buttress_z_length {:0.3f}".format(c['ext_buttress_face_ext_corner_length'], c['bell_face_height'], c['leg_length'], c['ext_buttress_z_length']))) sys.exit(2) # ext_buttress_face_bump_length if(c['ext_buttress_face_bump_length']>c['ext_buttress_y_position']+c['ext_buttress_y_length']): - print("ERR515: Error, ext_buttress_face_bump_length {:0.3f} is too big compare to ext_buttress_y_position {:0.3f} and ext_buttress_y_length {:0.3f}".format(c['ext_buttress_face_bump_length'], c['ext_buttress_y_position'], c['ext_buttress_y_length'])) + six.print_(("ERR515: Error, ext_buttress_face_bump_length {:0.3f} is too big compare to ext_buttress_y_position {:0.3f} and ext_buttress_y_length {:0.3f}".format(c['ext_buttress_face_bump_length'], c['ext_buttress_y_position'], c['ext_buttress_y_length']))) sys.exit(2) # ext_buttress_base_int_corner_length if(c['ext_buttress_base_int_corner_length']>c['ext_buttress_y_position']): - print("ERR519: Error, ext_buttress_base_int_corner_length {:0.3f} must be smaller than ext_buttress_y_position {:0.3f}".format(c['ext_buttress_base_int_corner_length'], c['ext_buttress_y_position'])) + six.print_(("ERR519: Error, ext_buttress_base_int_corner_length {:0.3f} must be smaller than ext_buttress_y_position {:0.3f}".format(c['ext_buttress_base_int_corner_length'], c['ext_buttress_y_position']))) sys.exit(2) # ext_buttress_base_ext_corner_length if(c['ext_buttress_base_ext_corner_length']>c['base_radius']-(c['bell_face_width']/2.0+c['ext_buttress_y_position']+c['ext_buttress_y_length'])): - print("ERR523: Error, ext_buttress_base_ext_corner_length {:0.3f} is too big compare to base_radius {:0.3f}, bell_face_width {:0.3f}, ext_buttress_y_position {:0.3f} and ext_buttress_y_length {:0.3f}".format(c['ext_buttress_base_ext_corner_length'], c['base_radius'], c['bell_face_width'], c['ext_buttress_y_position'], c['ext_buttress_y_length'])) + six.print_(("ERR523: Error, ext_buttress_base_ext_corner_length {:0.3f} is too big compare to base_radius {:0.3f}, bell_face_width {:0.3f}, ext_buttress_y_position {:0.3f} and ext_buttress_y_length {:0.3f}".format(c['ext_buttress_base_ext_corner_length'], c['base_radius'], c['bell_face_width'], c['ext_buttress_y_position'], c['ext_buttress_y_length']))) sys.exit(2) # ext_buttress_base_bump_length if(c['ext_buttress_base_bump_length']>c['ext_buttress_z_position']+c['ext_buttress_z_length']): - print("ERR527: Error, ext_buttress_base_bump_length {:0.3f} is too big compare to ext_buttress_z_position {:0.3f} and ext_buttress_z_length {:0.3f}".format(c['ext_buttress_base_bump_length'], c['ext_buttress_z_position'], c['ext_buttress_z_length'])) + six.print_(("ERR527: Error, ext_buttress_base_bump_length {:0.3f} is too big compare to ext_buttress_z_position {:0.3f} and ext_buttress_z_length {:0.3f}".format(c['ext_buttress_base_bump_length'], c['ext_buttress_z_position'], c['ext_buttress_z_length']))) sys.exit(2) # ext_buttress_arc_height if(abs(c['ext_buttress_arc_height'])>max(c['ext_buttress_z_length'], c['ext_buttress_y_length'])): - print("ERR531: Error, ext_buttress_arc_height {:0.3f} absolute value is too big compare to ext_buttress_z_length {:0.3f} and ext_buttress_y_length {:0.3f}".format(c['ext_buttress_arc_height'], c['ext_buttress_z_length'], c['ext_buttress_y_length'])) + six.print_(("ERR531: Error, ext_buttress_arc_height {:0.3f} absolute value is too big compare to ext_buttress_z_length {:0.3f} and ext_buttress_y_length {:0.3f}".format(c['ext_buttress_arc_height'], c['ext_buttress_z_length'], c['ext_buttress_y_length']))) sys.exit(2) # ext_buttress_smoothing_radius if(c['ext_buttress_smoothing_radius']>max(c['ext_buttress_face_bump_length'], c['ext_buttress_base_bump_length'])): - print("ERR535: Error, ext_buttress_smoothing_radius {:0.3f} is too big compare to ext_buttress_face_bump_length {:0.3f} and ext_buttress_base_bump_length {:0.3f}".format(c['ext_buttress_smoothing_radius'], c['ext_buttress_face_bump_length'], c['ext_buttress_base_bump_length'])) + six.print_(("ERR535: Error, ext_buttress_smoothing_radius {:0.3f} is too big compare to ext_buttress_face_bump_length {:0.3f} and ext_buttress_base_bump_length {:0.3f}".format(c['ext_buttress_smoothing_radius'], c['ext_buttress_face_bump_length'], c['ext_buttress_base_bump_length']))) sys.exit(2) # hollow_z_height if(c['hollow_z_height']>c['bell_face_height']): - print("ERR539: Error, hollow_z_height {:0.3f} must be smaller than bell_face_height {:0.3f}".format(c['hollow_z_height'], c['bell_face_height'])) + six.print_(("ERR539: Error, hollow_z_height {:0.3f} must be smaller than bell_face_height {:0.3f}".format(c['hollow_z_height'], c['bell_face_height']))) sys.exit(2) # hollow_y_width if(c['hollow_y_width']<2*c['bell_cnc_router_bit_radius']): - print("ERR543: Error, hollow_y_width {:0.3f} is too small compare to bell_cnc_router_bit_radius {:0.3f}".format(c['hollow_y_width'], c['bell_cnc_router_bit_radius'])) + six.print_(("ERR543: Error, hollow_y_width {:0.3f} is too small compare to bell_cnc_router_bit_radius {:0.3f}".format(c['hollow_y_width'], c['bell_cnc_router_bit_radius']))) sys.exit(2) if(c['hollow_y_width']>c['bell_face_width']-2*c['face_thickness']): - print("ERR546: Error, hollow_y_width {:0.3f} is too big compare to bell_face_width {:0.3f} and face_thickness {:0.3f}".format(c['hollow_y_width'], c['bell_face_width'], c['face_thickness'])) + six.print_(("ERR546: Error, hollow_y_width {:0.3f} is too big compare to bell_face_width {:0.3f} and face_thickness {:0.3f}".format(c['hollow_y_width'], c['bell_face_width'], c['face_thickness']))) sys.exit(2) # hollow_spare_width if(c['hollow_spare_width']>c['bell_face_width']/2-c['face_thickness']-c['hollow_y_width']/2.0): - print("ERR550: Error, hollow_spare_width {:0.3f} is too big compare to bell_face_width {:0.3f}, face_thickness {:0.3f} and hollow_y_width {:0.3f}".format(c['hollow_spare_width'], c['bell_face_width'], c['face_thickness'], c['hollow_y_width'])) + six.print_(("ERR550: Error, hollow_spare_width {:0.3f} is too big compare to bell_face_width {:0.3f}, face_thickness {:0.3f} and hollow_y_width {:0.3f}".format(c['hollow_spare_width'], c['bell_face_width'], c['face_thickness'], c['hollow_y_width']))) sys.exit(2) # base_hole_nb if(c['base_hole_nb']>0): # base_hole_diameter c['base_hole_radius'] = c['base_hole_diameter']/2.0 if(c['base_hole_radius']c['base_radius']-c['base_hole_radius']): - print("ERR567: Error, base_hole_position_radius {:0.3f} is too big compare to base_radius {:0.3f} and base_hole_radius {:0.3f}".format(c['base_hole_position_radius'], c['base_radius'], c['base_hole_radius'])) + six.print_(("ERR567: Error, base_hole_position_radius {:0.3f} is too big compare to base_radius {:0.3f} and base_hole_radius {:0.3f}".format(c['base_hole_position_radius'], c['base_radius'], c['base_hole_radius']))) sys.exit(2) # base_hole_angle # y_hole_diameter @@ -471,68 +472,68 @@ def bell_constraint_check(c): if(c['y_hole_radius']>0): # y_hole_z_top_position if(abs(c['y_hole_z_top_position'])>c['bell_face_height']): - print("ERR575: Error, y_hole_z_top_position {:0.3f} absolute value is too big compare to bell_face_height {:0.3f}".format(c['y_hole_z_top_position'], c['bell_face_height'])) + six.print_(("ERR575: Error, y_hole_z_top_position {:0.3f} absolute value is too big compare to bell_face_height {:0.3f}".format(c['y_hole_z_top_position'], c['bell_face_height']))) sys.exit(2) if(c['y_hole_z_top_position']>0): if(c['y_hole_z_top_position']-1*c['y_hole_radius']): - print("ERR584: Error, negative y_hole_z_top_position {:0.3f} must be smaller than y_hole_radius {:0.3f}".format(c['y_hole_z_top_position'], -1*c['y_hole_radius'])) + six.print_(("ERR584: Error, negative y_hole_z_top_position {:0.3f} must be smaller than y_hole_radius {:0.3f}".format(c['y_hole_z_top_position'], -1*c['y_hole_radius']))) sys.exit(2) # y_hole_z_bottom_position if(abs(c['y_hole_z_bottom_position'])>c['bell_face_height']): - print("ERR575: Error, y_hole_z_bottom_position {:0.3f} absolute value is too big compare to bell_face_height {:0.3f}".format(c['y_hole_z_bottom_position'], c['bell_face_height'])) + six.print_(("ERR575: Error, y_hole_z_bottom_position {:0.3f} absolute value is too big compare to bell_face_height {:0.3f}".format(c['y_hole_z_bottom_position'], c['bell_face_height']))) sys.exit(2) if(c['y_hole_z_bottom_position']>0): if(c['y_hole_z_bottom_position']-1*c['y_hole_radius']): - print("ERR584: Error, negative y_hole_z_bottom_position {:0.3f} must be smaller than y_hole_radius {:0.3f}".format(c['y_hole_z_bottom_position'], -1*c['y_hole_radius'])) + six.print_(("ERR584: Error, negative y_hole_z_bottom_position {:0.3f} must be smaller than y_hole_radius {:0.3f}".format(c['y_hole_z_bottom_position'], -1*c['y_hole_radius']))) sys.exit(2) # y_hole_x_position if(c['y_hole_x_position']c['bell_face_width']/2.0-c['side_thickness']): - print("ERR591: Error, y_hole_x_position {:0.3f} is too big compare to bell_face_width {:0.3f} and side_thickness {:0.3f}".format(c['y_hole_x_position'], c['bell_face_width'], c['side_thickness'])) + six.print_(("ERR591: Error, y_hole_x_position {:0.3f} is too big compare to bell_face_width {:0.3f} and side_thickness {:0.3f}".format(c['y_hole_x_position'], c['bell_face_width'], c['side_thickness']))) sys.exit(2) # x_hole_diameter c['x_hole_radius'] = c['x_hole_diameter']/2.0 if(c['x_hole_radius']>0): # x_hole_z_top_position if(abs(c['x_hole_z_top_position'])>c['bell_face_height']): - print("ERR598: Error, x_hole_z_top_position {:0.3f} absolute value is too big compare to bell_face_height {:0.3f}".format(c['x_hole_z_top_position'], c['bell_face_height'])) + six.print_(("ERR598: Error, x_hole_z_top_position {:0.3f} absolute value is too big compare to bell_face_height {:0.3f}".format(c['x_hole_z_top_position'], c['bell_face_height']))) sys.exit(2) if(c['x_hole_z_top_position']>0): if(c['x_hole_z_top_position']-1*c['x_hole_radius']): - print("ERR584: Error, negative x_hole_z_top_position {:0.3f} must be smaller than x_hole_radius {:0.3f}".format(c['x_hole_z_top_position'], -1*c['x_hole_radius'])) + six.print_(("ERR584: Error, negative x_hole_z_top_position {:0.3f} must be smaller than x_hole_radius {:0.3f}".format(c['x_hole_z_top_position'], -1*c['x_hole_radius']))) sys.exit(2) # x_hole_z_bottom_position if(abs(c['x_hole_z_bottom_position'])>c['bell_face_height']): - print("ERR598: Error, x_hole_z_bottom_position {:0.3f} absolute value is too big compare to bell_face_height {:0.3f}".format(c['x_hole_z_bottom_position'], c['bell_face_height'])) + six.print_(("ERR598: Error, x_hole_z_bottom_position {:0.3f} absolute value is too big compare to bell_face_height {:0.3f}".format(c['x_hole_z_bottom_position'], c['bell_face_height']))) sys.exit(2) if(c['x_hole_z_bottom_position']>0): if(c['x_hole_z_bottom_position']-1*c['x_hole_radius']): - print("ERR584: Error, negative x_hole_z_bottom_position {:0.3f} must be smaller than x_hole_radius {:0.3f}".format(c['x_hole_z_bottom_position'], -1*c['x_hole_radius'])) + six.print_(("ERR584: Error, negative x_hole_z_bottom_position {:0.3f} must be smaller than x_hole_radius {:0.3f}".format(c['x_hole_z_bottom_position'], -1*c['x_hole_radius']))) sys.exit(2) # x_hole_y_position if(c['x_hole_y_position']c['bell_face_width']/2.0-c['side_thickness']): - print("ERR591: Error, x_hole_y_position {:0.3f} is too big compare to bell_face_width {:0.3f} and side_thickness {:0.3f}".format(c['x_hole_y_position'], c['bell_face_width'], c['side_thickness'])) + six.print_(("ERR591: Error, x_hole_y_position {:0.3f} is too big compare to bell_face_width {:0.3f} and side_thickness {:0.3f}".format(c['x_hole_y_position'], c['bell_face_width'], c['side_thickness']))) sys.exit(2) # z_hole_diameter c['z_hole_radius'] = c['z_hole_diameter']/2.0 @@ -542,18 +543,18 @@ def bell_constraint_check(c): c['z_hole_external_radius'] = 2*c['z_hole_radius'] # z_hole_position_length if(c['z_hole_position_length']c['bell_face_width']/2.0): - print("ERR626: Error, z_hole_position_length {:0.3f} is too big compare to bell_face_width {:0.3f}".format(c['z_hole_position_length'], c['bell_face_width'])) + six.print_(("ERR626: Error, z_hole_position_length {:0.3f} is too big compare to bell_face_width {:0.3f}".format(c['z_hole_position_length'], c['bell_face_width']))) sys.exit(2) # bell_cnc_router_bit_radius if(c['bell_cnc_router_bit_radius']>min(c['face_thickness'], c['side_thickness'], c['base_thickness'])/2.0): - print("ERR634: Error, bell_cnc_router_bit_radius {:0.3f} is too big compare to face_thickness {:0.3f}, side_thickness {:0.3f} or base_thickness {:0.3f}".format(c['bell_cnc_router_bit_radius'], c['face_thickness'], c['side_thickness'], c['base_thickness'])) + six.print_(("ERR634: Error, bell_cnc_router_bit_radius {:0.3f} is too big compare to face_thickness {:0.3f}, side_thickness {:0.3f} or base_thickness {:0.3f}".format(c['bell_cnc_router_bit_radius'], c['face_thickness'], c['side_thickness'], c['base_thickness']))) sys.exit(2) # bell_extra_cut_thickness if(c['bell_extra_cut_thickness']>min(c['bell_face_width'], c['bell_face_height'])/10.0): - print("ERR630: Error, bell_extra_cut_thickness {:0.3f} is too big compare to bell_face_width {:0.3f} and bell_face_height {:0.3f}".format(c['bell_extra_cut_thickness'], c['bell_face_width'], c['bell_face_height'])) + six.print_(("ERR630: Error, bell_extra_cut_thickness {:0.3f} is too big compare to bell_face_width {:0.3f} and bell_face_height {:0.3f}".format(c['bell_extra_cut_thickness'], c['bell_face_width'], c['bell_face_height']))) sys.exit(2) ## intermediate parameters c['f_w2'] = c['bell_face_width']/2.0 @@ -896,7 +897,7 @@ def bell_cli_return_type(return_type, c): elif(return_type=='figures_3dconf_info'): r_b = (figures['part_list'], assembly_conf['bell_assembly_conf1'], b_info) else: - print("ERR508: Error the return_type {:s} is unknown".format(return_type)) + six.print_(("ERR508: Error the return_type {:s} is unknown".format(return_type))) sys.exit(2) return(r_b) diff --git a/cnc25d/bell_bagel_assembly.py b/cnc25d/bell_bagel_assembly.py index 5e25bf5..f952fe4 100644 --- a/cnc25d/bell_bagel_assembly.py +++ b/cnc25d/bell_bagel_assembly.py @@ -29,7 +29,8 @@ # header for Python / FreeCAD compatibility ################################################################ -import cnc25d_api +from . import cnc25d_api +import six cnc25d_api.importing_freecad() #print("FreeCAD.Version:", FreeCAD.Version()) @@ -52,8 +53,8 @@ #import svgwrite #from dxfwrite import DXFEngine # cnc25d -import bell -import bagel +from . import bell +from . import bagel ################################################################ # inheritance from designs bell and bagel @@ -117,7 +118,7 @@ def bba_constraint_check(c): # bagel_axle_diameter c['bagel_axle_radius'] = c['bagel_axle_diameter']/2.0 if(c['bagel_axle_radius']1): - print("ERR063: Error, cos_aBAC {:0.3f} is out of the range -1..1".format(cos_aBAC)) - print("dbg064: lAC {:0.3f} lAB {:0.3f}".format(lAC, lAB)) + six.print_(("ERR063: Error, cos_aBAC {:0.3f} is out of the range -1..1".format(cos_aBAC))) + six.print_(("dbg064: lAC {:0.3f} lAB {:0.3f}".format(lAC, lAB))) sys.exit(2) aBAC = math.acos(cos_aBAC) #lAD = math.sqrt(lAC**2-lCD**2) @@ -166,7 +167,7 @@ def bell_face_outline(ai_c): # angle (Gx, GH) axGH = math.atan2(Hy-Gy, Hx-Gx) if(abs(axGH+leg_ext_axle_angle)>radian_epsilon): # check axGH - print("ERR097: Error, axGH {:0.3f} is not equal to -1*leg_ext_axle_angle {:0.3f}".format(axGH, leg_ext_axle_angle)) + six.print_(("ERR097: Error, axGH {:0.3f} is not equal to -1*leg_ext_axle_angle {:0.3f}".format(axGH, leg_ext_axle_angle))) sys.exit(2) # angle (Gx, GE) axGE = math.atan2(Ey-Gy, Ex-Gx) @@ -359,12 +360,12 @@ def bell_base_main_hole_outline(ai_c): lCB = math.sqrt(lAB**2+lAC**2-2*lAB*lAC*math.cos(aBAC)) # law of cosines in the triangle ABC cos_aACB = (lCB**2+lAC**2-lAB**2)/(2*lCB*lAC) if(abs(cos_aACB)>1): - print("ERR359: Error, cos_aACB {:0.3f} is out of the range -1..1".format(cos_aACB)) + six.print_(("ERR359: Error, cos_aACB {:0.3f} is out of the range -1..1".format(cos_aACB))) sys.exit(2) aACB = math.acos(cos_aACB) cos_aBCD = lCD/lCB if(abs(cos_aBCD)>1): - print("ERR364: Error, cos_aBCD {:0.3f} is out of the range -1..1".format(cos_aBCD)) + six.print_(("ERR364: Error, cos_aBCD {:0.3f} is out of the range -1..1".format(cos_aBCD))) sys.exit(2) aBCD = math.acos(cos_aBCD) aACD = aACB + aBCD @@ -581,7 +582,7 @@ def bell_external_buttress(ai_c, ai_type): elif(ai_type=='side'): wall_thickness = ai_c['side_thickness'] else: - print("ERR527: Error, ai_type {:s} doesn't exist".format(ai_type)) + six.print_(("ERR527: Error, ai_type {:s} doesn't exist".format(ai_type))) sys.exit(2) ### outline construction b_p = {} diff --git a/cnc25d/box_wood_frame.py b/cnc25d/box_wood_frame.py index 797ff97..9a2156f 100644 --- a/cnc25d/box_wood_frame.py +++ b/cnc25d/box_wood_frame.py @@ -31,7 +31,7 @@ #import importing_freecad #importing_freecad.importing_freecad() -import cnc25d_api +from . import cnc25d_api cnc25d_api.importing_freecad() #print("FreeCAD.Version:", FreeCAD.Version()) @@ -47,7 +47,7 @@ #import os, errno #import os # -from box_wood_frame_outline import * +from .box_wood_frame_outline import * # import Part #from FreeCAD import Base diff --git a/cnc25d/box_wood_frame_ng.py b/cnc25d/box_wood_frame_ng.py index d0488ac..288e5fc 100644 --- a/cnc25d/box_wood_frame_ng.py +++ b/cnc25d/box_wood_frame_ng.py @@ -33,7 +33,8 @@ #import importing_freecad #importing_freecad.importing_freecad() -import cnc25d_api +from . import cnc25d_api +import six cnc25d_api.importing_freecad() #print("FreeCAD.Version:", FreeCAD.Version()) @@ -169,9 +170,9 @@ def box_wood_frame(ai_constraints): bwfdi = box_wood_frame_dictionary_init() bwf_c = bwfdi.copy() bwf_c.update(ai_constraints) - print("dbg155: bwf_c:", bwf_c) - if(len(bwf_c.viewkeys() & bwfdi.viewkeys()) != len(bwf_c.viewkeys() | bwfdi.viewkeys())): # check if the dictionary bwf_c has exactly all the keys compare to box_wood_frame_dictionary_init() - print("ERR157: Error, bwf_c has too much entries as {:s} or missing entries as {:s}".format(bwf_c.viewkeys() - bwfdi.viewkeys(), bwfdi.viewkeys() - bwf_c.viewkeys())) + six.print_(("dbg155: bwf_c:", bwf_c)) + if(len(bwf_c & bwfdi) != len(bwf_c | bwfdi)): # check if the dictionary bwf_c has exactly all the keys compare to box_wood_frame_dictionary_init() + six.print_(("ERR157: Error, bwf_c has too much entries as {:s} or missing entries as {:s}".format(bwf_c - bwfdi, bwfdi - bwf_c))) sys.exit(2) #print("dbg164: new box_wood_frame constraints:") #for k in bwf_c.viewkeys(): @@ -895,7 +896,7 @@ def plank_generic(nai_plank_name, nai_module_width, nai_cutting_extra): elif(nai_plank_name=="slab58_front"): r_plank = slab_front(nai_cutting_extra) else: - print("ERR115: Error, the plank_name {:s} doesn't exist".format(nai_plank_name)) + six.print_(("ERR115: Error, the plank_name {:s} doesn't exist".format(nai_plank_name))) sys.exit(2) return(r_plank) def place_plank_generic(nai_plank_name, nai_module_width, nai_cutting_extra, ai_flip, ai_orientation, ai_position_x, ai_position_y, ai_position_z): @@ -1163,7 +1164,7 @@ def plank_serie_place(ai_plank_list, nai_module_width, nai_cutting_extra, ai_ini elif(l_orientation=='yx'): l_inc_x = 1 else: - print("ERR564: the l_orientation {:s} doesn't exist!".format(l_orientation)) + six.print_(("ERR564: the l_orientation {:s} doesn't exist!".format(l_orientation))) sys.exit(2) for li in range(l_plank_desc[lp][3]): r_batch.append(place_plank_generic(lp, nai_module_width, nai_cutting_extra, 'i', l_orientation, l_pos_x, l_pos_y, ai_ini_z)) @@ -1477,7 +1478,7 @@ def box_wood_frame_text_report(nai_module_width, nai_args_in_txt): def fg_file_path(ai_output_dir, ai_file_name): r_file_path = "{:s}/{:s}".format(ai_output_dir, ai_file_name) - print("Generate the output file: {:s}".format(r_file_path)) + six.print_(("Generate the output file: {:s}".format(r_file_path))) return(r_file_path) def fg_text_report(ai_file_idx, ai_file_name, ai_file_description, ai_size): @@ -1593,7 +1594,7 @@ def box_wood_frame_file_generator(nai_output_file_basename, nai_args_in_txt): It returns a string that contains the file name list and their description. """ bwf_log = box_wood_frame_text_report(ai_module_width, nai_args_in_txt) - print("{:s}".format(bwf_log)) + six.print_(("{:s}".format(bwf_log))) l_text_report = bwf_log #print("dbg747: nai_output_file_basename:", nai_output_file_basename) if(nai_output_file_basename==""): @@ -1738,7 +1739,7 @@ def box_wood_frame_file_generator(nai_output_file_basename, nai_args_in_txt): #r_bwf = frame_assembly(ai_module_width,ai_cutting_extra,0) #Part.show(r_bwf) else: - print("ERR736: Error, return_type {:s} is unknown".format(bwf_c['return_type'])) + six.print_(("ERR736: Error, return_type {:s} is unknown".format(bwf_c['return_type']))) sys.exit(2) #r_bwf.exportStl("bwf_assembly.stl") #r_bwf = plank_tobo_diagonal(0) @@ -1818,7 +1819,7 @@ def box_wood_frame_self_test(): bwf_parser = box_wood_frame_add_argument(bwf_parser) for i in range(len(test_case_switch)): l_test_switch = test_case_switch[i][1] - print("{:2d} test case: '{:s}'\nwith switch: {:s}".format(i, test_case_switch[i][0], l_test_switch)) + six.print_(("{:2d} test case: '{:s}'\nwith switch: {:s}".format(i, test_case_switch[i][0], l_test_switch))) l_args = l_test_switch.split() #print("dbg414: l_args:", l_args) st_args = bwf_parser.parse_args(l_args) diff --git a/cnc25d/box_wood_frame_outline.py b/cnc25d/box_wood_frame_outline.py index 03ffea2..c785915 100644 --- a/cnc25d/box_wood_frame_outline.py +++ b/cnc25d/box_wood_frame_outline.py @@ -30,7 +30,7 @@ #import importing_freecad #importing_freecad.importing_freecad() -import cnc25d_api +from . import cnc25d_api cnc25d_api.importing_freecad() #print("FreeCAD.Version:", FreeCAD.Version()) diff --git a/cnc25d/cnc25d_api.py b/cnc25d/cnc25d_api.py index b8c8a76..2cbf3ce 100644 --- a/cnc25d/cnc25d_api.py +++ b/cnc25d/cnc25d_api.py @@ -29,16 +29,16 @@ # import ################################################################ -import importing_freecad -import cnc_outline -import outline_backends -import positioning -import export_2d -import design_output -import design_help -import bare_design -import design_frontend -import draw_2d_frontend +from . import importing_freecad +from . import cnc_outline +from . import outline_backends +from . import positioning +from . import export_2d +from . import design_output +from . import design_help +from . import bare_design +from . import design_frontend +from . import draw_2d_frontend ################################################################ # api function alias diff --git a/cnc25d/cnc25d_design.py b/cnc25d/cnc25d_design.py index 6034ae5..313099b 100644 --- a/cnc25d/cnc25d_design.py +++ b/cnc25d/cnc25d_design.py @@ -29,22 +29,22 @@ # import ################################################################ -import box_wood_frame -import gear_profile -import gearwheel -import gearring -import gearbar -import split_gearwheel -import epicyclic_gearing -import axle_lid -import motor_lid -import bell -import bagel -import bell_bagel_assembly -import crest -import cross_cube -import gimbal -import low_torque_transmission +from . import box_wood_frame +from . import gear_profile +from . import gearwheel +from . import gearring +from . import gearbar +from . import split_gearwheel +from . import epicyclic_gearing +from . import axle_lid +from . import motor_lid +from . import bell +from . import bagel +from . import bell_bagel_assembly +from . import crest +from . import cross_cube +from . import gimbal +from . import low_torque_transmission ################################################################ # Cnc25d Designs diff --git a/cnc25d/cnc_outline.py b/cnc25d/cnc_outline.py index bbb4717..bee53e0 100644 --- a/cnc25d/cnc_outline.py +++ b/cnc25d/cnc_outline.py @@ -28,7 +28,7 @@ # python behavior ################################################################ -from __future__ import division # to get float division + # to get float division ################################################################ # header for Python / FreeCAD compatibility @@ -54,8 +54,9 @@ import math import sys, argparse # -import design_help # just for get_effective_args() -from small_geometry import * +from . import design_help # just for get_effective_args() +from .small_geometry import * +import six ################################################################ # ******** Sub-functions for the API *********** @@ -69,7 +70,7 @@ def check_outline_format(ai_outline): # check if it is a format-B circle if(not isinstance(ai_outline, (tuple, list))): print("ERR937: Error, ai_outline must be a list or a tuple") - print("dbg072: ai_outline:", ai_outline) + six.print_(("dbg072: ai_outline:", ai_outline)) sys.exit(2) # check if the outline contains at least on element if(len(ai_outline)==0): @@ -79,8 +80,8 @@ def check_outline_format(ai_outline): if(isinstance(ai_outline[0], (tuple, list))): # general outline # checks on ai_outline for general outline if(len(ai_outline)<2): - print("ERR402: Error, the segment list must contain at least 2 elements. Currently, len(ai_outline) = {:d}".format(len(ai_outline))) - print("dbg082: ai_outline:", ai_outline) + six.print_(("ERR402: Error, the segment list must contain at least 2 elements. Currently, len(ai_outline) = {:d}".format(len(ai_outline)))) + six.print_(("dbg082: ai_outline:", ai_outline)) sys.exit(2) # check the first point len_first_point = len(ai_outline[0]) @@ -89,12 +90,12 @@ def check_outline_format(ai_outline): elif(len_first_point==3): r_outline_type = 2 else: - print("ERR457: Error, the first point has an unexpected number of items {:d}".format(len_first_point)) + six.print_(("ERR457: Error, the first point has an unexpected number of items {:d}".format(len_first_point))) #print("dbg093: ai_outline:", ai_outline) sys.exit(2) else: # circle outline if(len(ai_outline)!=3): - print("ERR758: Error, circle outline must be a list of 3 floats (or int)! Current len: {:d}".format(len(ai_outline))) + six.print_(("ERR758: Error, circle outline must be a list of 3 floats (or int)! Current len: {:d}".format(len(ai_outline)))) sys.exit(2) r_outline_type = 0 return(r_outline_type) @@ -125,7 +126,7 @@ def reverse_outline(ai_outline): elif(len_p==4): is_arc = True else: - print("ERR257: Error, the segment has an unxepected number of items {:d}".format(len_p)) + six.print_(("ERR257: Error, the segment has an unxepected number of items {:d}".format(len_p))) sys.exit(2) elif(outline_type==2): if(len_p==3): @@ -133,7 +134,7 @@ def reverse_outline(ai_outline): elif(len_p==5): is_arc = True else: - print("ERR258: Error, the segment has an unxepected number of items {:d}".format(len_p)) + six.print_(("ERR258: Error, the segment has an unxepected number of items {:d}".format(len_p))) sys.exit(2) #else: # print("ERR557: Error, the outline_type is unexpected {:d}".format(outline_type)) @@ -179,7 +180,7 @@ def reverse_outline(ai_outline): if(outline_closed): if(outline_type==2): if(r_outline[0][2]!=0): - print("WARN567: Warning, the last router_bit request of the closed outline is not set to zero: {:0.2f}".format(r_outline[0][2])) + six.print_(("WARN567: Warning, the last router_bit request of the closed outline is not set to zero: {:0.2f}".format(r_outline[0][2]))) r_outline[0]=(r_outline[0][0], r_outline[0][1], r_outline[-1][-1]) last_segment = list(r_outline[-1]) last_segment[-1] = 0 @@ -203,22 +204,22 @@ def smooth_corner_line_line(ai_pre_point, ai_current_point, ai_post_point, ai_ro # corner angle #if(AG==0): if(AG(1+radian_epsilon)): - print("ERR210: Error with math.acos {:0.5f}".format((AG**2+AH**2-GH**2)/(2*AH*AG))) - print("dbg211: AG {:0.3f} AH {:0.3f} GH {:0.3f}".format(AG, AH, GH)) + six.print_(("ERR210: Error with math.acos {:0.5f}".format((AG**2+AH**2-GH**2)/(2*AH*AG)))) + six.print_(("dbg211: AG {:0.3f} AH {:0.3f} GH {:0.3f}".format(AG, AH, GH))) sys.exit(2) elif(corner_cos>=1): corner_angle = 0 @@ -228,16 +229,16 @@ def smooth_corner_line_line(ai_pre_point, ai_current_point, ai_post_point, ai_ro corner_angle = math.acos(corner_cos) #print("dbg206: corner_angle:", corner_angle) if(corner_angle>math.pi-radian_epsilon): - print("WARN673: Warning, the corner angle {:s} is too flat and won't be smoothed!".format(ai_error_msg_id)) + six.print_(("WARN673: Warning, the corner angle {:s} is too flat and won't be smoothed!".format(ai_error_msg_id))) r_outline = [(AX, AY)] elif(corner_anglemath.pi-radian_epsilon): - print("WARN573: Warning, the corner angle {:s} is too flat and won't be enlarged!".format(ai_error_msg_id)) + six.print_(("WARN573: Warning, the corner angle {:s} is too flat and won't be enlarged!".format(ai_error_msg_id))) r_outline = [(AX, AY)] elif(corner_anglemath.pi/2-radian_epsilon): # enlarge obtuse angle # AE ( = AF = 2*r*cos(a/2) ) AE = 2*ai_router_bit_request*math.cos(corner_angle/2) if((AGradian_epsilon)or(abs(IB-arc_radius)>radian_epsilon)or(abs(IC-arc_radius)>radian_epsilon)): - print("ERR831: Error, in {:s}, I is not equidistant from A,B,C,D,E. IA={:0.2f} IB={:0.2f} IC={:0.2f}".format(ai_error_msg_id, IA, IB, IC)) + six.print_(("ERR831: Error, in {:s}, I is not equidistant from A,B,C,D,E. IA={:0.2f} IB={:0.2f} IC={:0.2f}".format(ai_error_msg_id, IA, IB, IC))) sys.exit(2) if((abs(ID-IA)>radian_epsilon)or(abs(IE-IA)>radian_epsilon)): - print("ERR832: Error, in {:s}, I is not equidistant from A,B,C,D,E. IA={:0.2f} IB={:0.2f} IC={:0.2f} ID={:0.2f} IE={:0.2f}".format(error_msg_id, IA, IB, IC, ID, IE)) - print("dbg414: AX {:0.2f} AY {:0.2f}".format(AX,AY)) - print("dbg424: BX {:0.2f} BY {:0.2f}".format(BX,BY)) - print("dbg434: CX {:0.2f} CY {:0.2f}".format(CX,CY)) - print("dbg444: DX {:0.2f} DY {:0.2f}".format(DX,DY)) - print("dbg454: EX {:0.2f} EY {:0.2f}".format(EX,EY)) - print("dbg464: IX {:0.2f} IY {:0.2f}".format(IX,IY)) + six.print_(("ERR832: Error, in {:s}, I is not equidistant from A,B,C,D,E. IA={:0.2f} IB={:0.2f} IC={:0.2f} ID={:0.2f} IE={:0.2f}".format(error_msg_id, IA, IB, IC, ID, IE))) + six.print_(("dbg414: AX {:0.2f} AY {:0.2f}".format(AX,AY))) + six.print_(("dbg424: BX {:0.2f} BY {:0.2f}".format(BX,BY))) + six.print_(("dbg434: CX {:0.2f} CY {:0.2f}".format(CX,CY))) + six.print_(("dbg444: DX {:0.2f} DY {:0.2f}".format(DX,DY))) + six.print_(("dbg454: EX {:0.2f} EY {:0.2f}".format(EX,EY))) + six.print_(("dbg464: IX {:0.2f} IY {:0.2f}".format(IX,IY))) sys.exit(2) # calculation of the angles d=(Ix, ID) and e=(Ix, IE) d = math.atan2(DY-IY, DX-IX) @@ -540,21 +541,21 @@ def arc_middle(ai_arc_pt1, ai_arc_pt2, ai_arc_pt3, ai_new_end1, ai_new_end2, ai_ ue = math.fmod(e-u+4*math.pi, 2*math.pi) # correction because of calculation imprecision if(abs(ud)>2*math.pi-radian_epsilon): - print("WARN771: Warning in {:s}, the angle ud is corrected to zero because of presumed calculation imprecision!".format(error_msg_id)) + six.print_(("WARN771: Warning in {:s}, the angle ud is corrected to zero because of presumed calculation imprecision!".format(error_msg_id))) ud = 0 arc_middle_status = 1 # check if E and F below to the arc segment A,B,C if((abs(uw)abs(ue)): - print("dbg539: u {:0.3f} uw {:0.3f} w {:0.3f} d {:0.3f} e {:0.3f}".format(u, uw, w, d, e)) - print("dbg540: AX {:0.3f} AY {:0.3f} BX {:0.3f} BY {:0.3f} CX {:0.3f} CY {:0.3f} DX {:0.3f} DY {:0.3f} EX {:0.3f} EY {:0.3f}".format(AX, AY, BX, BY, CX, CY, DX, DY, EX, EY)) - print("dbg541: ud {:0.3f} ue {:0.3f}".format(ud, ue)) - print("ERR442: Error, in {:s}, E,F have not the same orientation as A,B,C! ud={:0.2f} ue={:0.2f}".format(error_msg_id, ud, ue)) + six.print_(("dbg539: u {:0.3f} uw {:0.3f} w {:0.3f} d {:0.3f} e {:0.3f}".format(u, uw, w, d, e))) + six.print_(("dbg540: AX {:0.3f} AY {:0.3f} BX {:0.3f} BY {:0.3f} CX {:0.3f} CY {:0.3f} DX {:0.3f} DY {:0.3f} EX {:0.3f} EY {:0.3f}".format(AX, AY, BX, BY, CX, CY, DX, DY, EX, EY))) + six.print_(("dbg541: ud {:0.3f} ue {:0.3f}".format(ud, ue))) + six.print_(("ERR442: Error, in {:s}, E,F have not the same orientation as A,B,C! ud={:0.2f} ue={:0.2f}".format(error_msg_id, ud, ue))) #sys.exit(2) arc_middle_status = 2 # calculation of the angle de=(ID, IE) @@ -563,7 +564,7 @@ def arc_middle(ai_arc_pt1, ai_arc_pt2, ai_arc_pt3, ai_new_end1, ai_new_end2, ai_ else: de = math.fmod(e-d+4*math.pi, 2*math.pi) if(arc_middle_status == 2): - print("dbg550: de {:0.3f} arc_radius {:0.3f}".format(de, arc_radius)) + six.print_(("dbg550: de {:0.3f} arc_radius {:0.3f}".format(de, arc_radius))) # calculation of the angle f=(Ix, IF)=(Ix, ID)+(ID, IF) f = d + de/2 # calculation of F @@ -571,7 +572,7 @@ def arc_middle(ai_arc_pt1, ai_arc_pt2, ai_arc_pt3, ai_new_end1, ai_new_end2, ai_ FY = IY+arc_radius*math.sin(f) # dummy F in case of error if(arc_middle_status==2): - print("ERR221: Error in {:s} during the recalculation of the arc middle point!".format(error_msg_id)) + six.print_(("ERR221: Error in {:s} during the recalculation of the arc middle point!".format(error_msg_id))) sys.exit(2) #print("WARN221: Warning in {:s}, creating a dummy arc because of internal error!".format(error_msg_id)) #lDE = math.sqrt((EX-DX)**2+(EY-DY)**2) @@ -592,7 +593,7 @@ def general_outline_shift_xy(ai_outline, ai_x_offset, ai_x_coefficient, ai_y_off """ # check the parameters if((ai_x_coefficient==0)or(ai_y_coefficient==0)): - print("ERR439: Error, a multiplication coefficient is set to zero: {:0.2f} {:0.2f}".format(ai_x_coefficient, ai_y_coefficient)) + six.print_(("ERR439: Error, a multiplication coefficient is set to zero: {:0.2f} {:0.2f}".format(ai_x_coefficient, ai_y_coefficient))) sys.exit(2) # check if the outline must be reversed if((ai_x_coefficient*ai_y_coefficient)<0): @@ -615,7 +616,7 @@ def general_outline_shift_xy(ai_outline, ai_x_offset, ai_x_coefficient, ai_y_off elif(len_p==4): is_arc = True else: - print("ERR237: Error, the segment has an unxepected number of items {:d}".format(len_p)) + six.print_(("ERR237: Error, the segment has an unxepected number of items {:d}".format(len_p))) sys.exit(2) elif(outline_type==2): if(len_p==3): @@ -623,10 +624,10 @@ def general_outline_shift_xy(ai_outline, ai_x_offset, ai_x_coefficient, ai_y_off elif(len_p==5): is_arc = True else: - print("ERR247: Error, the segment has an unxepected number of items {:d}".format(len_p)) + six.print_(("ERR247: Error, the segment has an unxepected number of items {:d}".format(len_p))) sys.exit(2) else: - print("ERR257: Error, the outline_type is unexpected {:d}".format(outline_type)) + six.print_(("ERR257: Error, the outline_type is unexpected {:d}".format(outline_type))) sys.exit(2) # extract segments end_point = [] @@ -673,7 +674,7 @@ def general_outline_rotate(ai_outline, ai_ox, ai_oy, ai_rotation_angle): elif(len_p==4): is_arc = True else: - print("ERR237: Error, the segment has an unxepected number of items {:d}".format(len_p)) + six.print_(("ERR237: Error, the segment has an unxepected number of items {:d}".format(len_p))) sys.exit(2) elif(outline_type==2): if(len_p==3): @@ -681,10 +682,10 @@ def general_outline_rotate(ai_outline, ai_ox, ai_oy, ai_rotation_angle): elif(len_p==5): is_arc = True else: - print("ERR247: Error, the segment has an unxepected number of items {:d}".format(len_p)) + six.print_(("ERR247: Error, the segment has an unxepected number of items {:d}".format(len_p))) sys.exit(2) else: - print("ERR257: Error, the outline_type is unexpected {:d}".format(outline_type)) + six.print_(("ERR257: Error, the outline_type is unexpected {:d}".format(outline_type))) sys.exit(2) # extract segments end_point = [] @@ -722,7 +723,7 @@ def outline_shift_xy(ai_outline, ai_x_offset, ai_x_coefficient, ai_y_offset, ai_ outline_type = check_outline_format(ai_outline) if(outline_type==0): # it's a format-B circle if(abs(ai_x_coefficient)!=abs(ai_y_coefficient)): - print("WARN358: Warning, circle is scaled with different scale along x and y! {:0.2f} {:0.2f}".format(ai_x_coefficient, ai_y_coefficient)) + six.print_(("WARN358: Warning, circle is scaled with different scale along x and y! {:0.2f} {:0.2f}".format(ai_x_coefficient, ai_y_coefficient))) circle_center_x = ai_outline[0] circle_center_y = ai_outline[1] circle_radius = ai_outline[2] @@ -834,14 +835,14 @@ def cnc_cut_outline(ai_segment_list, ai_error_msg_id): segment_nb = point_nb-1 # check of the outline size if(segment_nb<1): - print("ERR202: Error in {:s}, the number of segments must be bigger than 1. Currently: {:d}".format(ai_error_msg_id, segment_nb)) + six.print_(("ERR202: Error in {:s}, the number of segments must be bigger than 1. Currently: {:d}".format(ai_error_msg_id, segment_nb))) sys.exit(2) if((segment_nb<2)and(outline_closed)): - print("ERR203: Error in {:s}, the number of segments must be bigger than 2 with a closed outline. Currently: {:d}".format(ai_error_msg_id, point_nb)) + six.print_(("ERR203: Error in {:s}, the number of segments must be bigger than 2 with a closed outline. Currently: {:d}".format(ai_error_msg_id, point_nb))) sys.exit(2) # check the start point if(len(ai_segment_list[0])!=3): - print("ERR564: the start point is not defined with three floats. {:d}".format(len(ai_segment_list[0]))) + six.print_(("ERR564: the start point is not defined with three floats. {:d}".format(len(ai_segment_list[0])))) sys.exit(2) # extract segment data pt_end = [] @@ -857,19 +858,19 @@ def cnc_cut_outline(ai_segment_list, ai_error_msg_id): (mid_pt_x, mid_pt_y, end_pt_x, end_pt_y, end_pt_r) = ai_segment_list[pt_idx] mid_elem = (mid_pt_x, mid_pt_y) else: - print("ERR563: Error, the segment is defined with an unexpected number of float {:d}".format(len_segment)) + six.print_(("ERR563: Error, the segment is defined with an unexpected number of float {:d}".format(len_segment))) sys.exit(2) pt_end.append((end_pt_x,end_pt_y)) pt_request.append(end_pt_r) pt_mid.append(mid_elem) # check router_bit request of first and last point if((pt_request[0]!=0)and(not outline_closed)): - print("WARN946: Warning, in {:s}, the router_bit request of the start point of the open outline is not zero: {:0.2f}".format(ai_error_msg_id, pt_request[0])) + six.print_(("WARN946: Warning, in {:s}, the router_bit request of the start point of the open outline is not zero: {:0.2f}".format(ai_error_msg_id, pt_request[0]))) pt_request[0]=0 # if the outline is open, the router_bit request of the last point has no signification # if the outline is closed, the router_bit request of the last point is ignore. and the router_bit request of the first point is used if(pt_request[-1]!=0): - print("WARN947: Warning, in {:s}, the router_bit request of the last point of the outline is not zero: {:0.2f}".format(ai_error_msg_id, pt_request[-1])) + six.print_(("WARN947: Warning, in {:s}, the router_bit request of the last point of the outline is not zero: {:0.2f}".format(ai_error_msg_id, pt_request[-1]))) pt_request[-1]=0 # build outline r_outline = [] @@ -945,13 +946,13 @@ def approximate_curve_tangent(ai_polyline, ai_error_msg_id): point_nb = len(ai_polyline) # check the outline point number if(point_nb<2): - print("ERR309: Error in {:s}, the number of points must be bigger than 2. Currently: {:d}".format(ai_error_msg_id, point_nb)) + six.print_(("ERR309: Error in {:s}, the number of points must be bigger than 2. Currently: {:d}".format(ai_error_msg_id, point_nb))) sys.exit(2) # check if ai_polyline is valid for i in range(len(ai_polyline)): point_len = len(ai_polyline[i]) if(point_len!=2): - print("ERR319: Error in {:s}, the point {:d} of ai_polyline must have exactly 2 elements. Currently: {:d}".format(ai_error_msg_id, i, point_len)) + six.print_(("ERR319: Error in {:s}, the point {:d} of ai_polyline must have exactly 2 elements. Currently: {:d}".format(ai_error_msg_id, i, point_len))) sys.exit(2) # processing initialization r_outline = [] @@ -967,7 +968,7 @@ def approximate_curve_tangent(ai_polyline, ai_error_msg_id): tangent_inclination2 = math.atan2((post2_point[1]-pre_point[1])/segment_length, (post2_point[0]-pre_point[0])/segment_length) tangent_inclination2_diff = math.fmod(tangent_inclination2-tangent_inclination+5*math.pi, 2*math.pi) - math.pi if(abs(tangent_inclination2_diff)>math.pi/3): - print("ERR315: Error in {:s}, the tangent_inclination is changing too fast for a curve approximation. tangent_inclination: {:0.2f} tangent_inclination2: {:0.2f}".format(ai_error_msg_id, tangent_inclination, tangent_inclination2)) + six.print_(("ERR315: Error in {:s}, the tangent_inclination is changing too fast for a curve approximation. tangent_inclination: {:0.2f} tangent_inclination2: {:0.2f}".format(ai_error_msg_id, tangent_inclination, tangent_inclination2))) sys.exit(2) tangent_inclination = math.fmod(tangent_inclination-1*tangent_inclination2_diff/2 + 5*math.pi, 2*math.pi) - math.pi r_outline.append((ai_polyline[0][0], ai_polyline[0][1], tangent_inclination)) # first-point @@ -993,7 +994,7 @@ def approximate_curve_tangent(ai_polyline, ai_error_msg_id): tangent_inclination2 = math.atan2((post_point[1]-pre2_point[1])/segment_length, (post_point[0]-pre2_point[0])/segment_length) tangent_inclination2_diff = math.fmod(tangent_inclination2-tangent_inclination+5*math.pi, 2*math.pi) - math.pi if(abs(tangent_inclination2_diff)>math.pi/3): - print("ERR315: Error in {:s}, the tangent_inclination is changing too fast for a curve approximation. tangent_inclination: {:0.2f} tangent_inclination2: {:0.2f}".format(ai_error_msg_id, tangent_inclination, tangent_inclination2)) + six.print_(("ERR315: Error in {:s}, the tangent_inclination is changing too fast for a curve approximation. tangent_inclination: {:0.2f} tangent_inclination2: {:0.2f}".format(ai_error_msg_id, tangent_inclination, tangent_inclination2))) sys.exit(2) tangent_inclination = math.fmod(tangent_inclination-1*tangent_inclination2_diff/2 + 5*math.pi, 2*math.pi) - math.pi r_outline.append((ai_polyline[-1][0], ai_polyline[-1][1], tangent_inclination)) # end-point @@ -1045,13 +1046,13 @@ def ideal_outline(ai_outline, ai_error_msg_id): # check the segment length segment_len = len(i_segment) if((segment_len!=3)and(segment_len!=5)): - print("ERR868: Error in {:s}.{:d}, len(segment_len) is not 3 or 5!".format(ai_error_msg_id, i)) + six.print_(("ERR868: Error in {:s}.{:d}, len(segment_len) is not 3 or 5!".format(ai_error_msg_id, i))) sys.exit(2) i += 1 # construct the ideal outline r_outline.append(i_segment[:-1]) # remove the third or the fifth element else: # format-B circle or format-B general outline - print("WARN441: Warning in {:s}, nothing to do, the outline is already in format-B".format(ai_error_msg_id)) + six.print_(("WARN441: Warning in {:s}, nothing to do, the outline is already in format-B".format(ai_error_msg_id))) r_outline = ai_outline return(r_outline) @@ -1064,14 +1065,14 @@ def ideal_outline(ai_outline, ai_error_msg_id): # addition import for the tests ################################################################ -import importing_freecad +from . import importing_freecad importing_freecad.importing_freecad() # import Part from FreeCAD import Base # -import Tkinter -import outline_backends +from six.moves import tkinter +from . import outline_backends # #import timeit #import cProfile @@ -1117,7 +1118,7 @@ def make_H_shape(ai_origin_x, ai_origin_y, ai_router_bit_r, ai_height, ai_output Part.show(myh_solid) # works only with FreeCAD GUI, ignore otherwise if(ai_output_file!=''): myh_solid.exportStl(ai_output_file) - print("output stl file: %s"%(ai_output_file)) + six.print_(("output stl file: %s"%(ai_output_file))) def make_X_shape(ai_origin_x, ai_origin_y, ai_router_bit_r, ai_height, ai_output_file): """ design a X-shape to test not 90 degree angles with the function cnc_cut_outline() @@ -1154,7 +1155,7 @@ def make_X_shape(ai_origin_x, ai_origin_y, ai_router_bit_r, ai_height, ai_output Part.show(myx_solid) # works only with FreeCAD GUI, ignore otherwise if(ai_output_file!=''): myx_solid.exportStl(ai_output_file) - print("output stl file: %s"%(ai_output_file)) + six.print_(("output stl file: %s"%(ai_output_file))) def make_M_shape(ai_origin_x, ai_origin_y, ai_router_bit_r, ai_height, ai_output_file): """ design a M-shape to test the three outline_shift_x, _y and _xy functions @@ -1201,7 +1202,7 @@ def make_M_shape(ai_origin_x, ai_origin_y, ai_router_bit_r, ai_height, ai_output Part.show(myx_solid) # works only with FreeCAD GUI, ignore otherwise if(ai_output_file!=''): myx_solid.exportStl(ai_output_file) - print("output stl file: %s"%(ai_output_file)) + six.print_(("output stl file: %s"%(ai_output_file))) def cnc_cut_outline_test1(): """ First test to check the cnc_cut_outline API @@ -1209,7 +1210,7 @@ def cnc_cut_outline_test1(): ### check the cnc_cut_outline function with several router_bit diameter y_offset = 0 for ir in [2.0, 1.5, 1.0, 0, -1.0, -2.0]: - print("dbg603: test with router_bit radius (ir):", ir) + six.print_(("dbg603: test with router_bit radius (ir):", ir)) make_H_shape( 0, y_offset, ir, 2, "self_test_cnc_cut_outline_H_r%0.2f.stl"%ir) make_X_shape(50, y_offset, ir, 2, "self_test_cnc_cut_outline_X_r%0.2f.stl"%ir) make_M_shape(150, y_offset, ir, 2, "self_test_cnc_cut_outline_M_r%0.2f.stl"%ir) @@ -1238,7 +1239,7 @@ def cnc_cut_outline_test3(ai_sw_router_bit_radius): """ Third test to check the cnc_cut_outline API It displays the shapes with Tkinter """ - print("Run test_3 with ai_sw_router_bit_radius={:0.2f} ...".format(ai_sw_router_bit_radius)) + six.print_(("Run test_3 with ai_sw_router_bit_radius={:0.2f} ...".format(ai_sw_router_bit_radius))) def outline_a(ai_router_bit_radius): corner_a=[ [0,20, ai_router_bit_radius], @@ -1332,7 +1333,7 @@ def outline_a(ai_router_bit_radius): outline_e2 = smooth_outline_b_curve(first_curve, radian_precision, ai_sw_router_bit_radius, 'cnc_cut_outline_test3_e2') # display with Tkinter - tk_root = Tkinter.Tk() + tk_root = tkinter.Tk() my_canvas = outline_backends.Two_Canvas(tk_root) # callback function for display_backend def sub_canvas_graphics(ai_rotation_direction, ai_angle_position): @@ -1374,7 +1375,7 @@ def measure_the_execution_time_of_the_sub_canvas_graphics_function(ai_repeat_nb) for i in range(ai_repeat_nb): tmp = sub_canvas_graphics(1, i*math.pi/200) time_stop = time.clock() - print("dbg507: time sub_canvas_graphics:", time_stop-time_start) + six.print_(("dbg507: time sub_canvas_graphics:", time_stop-time_start)) #measure_the_execution_time_of_the_sub_canvas_graphics_function(100) # end of measurement my_canvas.add_canvas_graphic_function(sub_canvas_graphics) @@ -1387,7 +1388,7 @@ def cnc_cut_outline_test4(ai_sw_router_bit_radius): """ Fourth test suggests small shapes, useful to develop the cnc_cut_outline API It displays the shapes with Tkinter """ - print("Run test_4 with ai_sw_router_bit_radius={:0.2f} ...".format(ai_sw_router_bit_radius)) + six.print_(("Run test_4 with ai_sw_router_bit_radius={:0.2f} ...".format(ai_sw_router_bit_radius))) def outline_t4_a(ai_router_bit_radius): three_arcs=[ [0,20, 0], @@ -1435,7 +1436,7 @@ def outline_t4_a(ai_router_bit_radius): # print("dbg332: outline_a2 i_segment:", len(i_segment), i_segment) # display with Tkinter - tk_root = Tkinter.Tk() + tk_root = tkinter.Tk() my_canvas = outline_backends.Two_Canvas(tk_root) # callback function for display_backend def sub_canvas_graphics_t4(ai_rotation_direction, ai_angle_position): @@ -1458,7 +1459,7 @@ def cnc_cut_outline_test5(ai_sw_router_bit_radius): It displays the shapes with Tkinter """ radian_precision = math.pi/100 - print("Run test_5 with ai_sw_router_bit_radius={:0.2f} ...".format(ai_sw_router_bit_radius)) + six.print_(("Run test_5 with ai_sw_router_bit_radius={:0.2f} ...".format(ai_sw_router_bit_radius))) first_curve=[ [20,0], [22,10], @@ -1476,7 +1477,7 @@ def cnc_cut_outline_test5(ai_sw_router_bit_radius): # print("dbg332: outline_a2 i_segment:", len(i_segment), i_segment) # display with Tkinter - tk_root = Tkinter.Tk() + tk_root = tkinter.Tk() my_canvas = outline_backends.Two_Canvas(tk_root) # callback function for display_backend def sub_canvas_graphics_t5(ai_rotation_direction, ai_angle_position): diff --git a/cnc25d/crest.py b/cnc25d/crest.py index 9426b3f..17faf8a 100644 --- a/cnc25d/crest.py +++ b/cnc25d/crest.py @@ -29,7 +29,8 @@ # header for Python / FreeCAD compatibility ################################################################ -import cnc25d_api +from . import cnc25d_api +import six cnc25d_api.importing_freecad() #print("FreeCAD.Version:", FreeCAD.Version()) @@ -52,8 +53,8 @@ #import svgwrite #from dxfwrite import DXFEngine # cnc25d -import cross_cube_sub -import gear_profile +from . import cross_cube_sub +from . import gear_profile ################################################################ @@ -150,11 +151,11 @@ def crest_constraint_check(c): ### outline #gear_module if(c['gear_module']maximal_gear_portion_angle): - print("ERR208: Error, portion_tooth_nb {:d} is too big compare to gear_module {:0.3f}, virtual_tooth_nb {:d}, free_mounting_width {:0.3f} and cube_width {:0.3f}".format(c['portion_tooth_nb'], c['gear_module'], c['virtual_tooth_nb'], c['free_mounting_width'], c['cube_width'])) + six.print_(("ERR208: Error, portion_tooth_nb {:d} is too big compare to gear_module {:0.3f}, virtual_tooth_nb {:d}, free_mounting_width {:0.3f} and cube_width {:0.3f}".format(c['portion_tooth_nb'], c['gear_module'], c['virtual_tooth_nb'], c['free_mounting_width'], c['cube_width']))) sys.exit(2) #free_mounting_width if(c['free_mounting_width']gear_hollow_radius): - print("ERR215: Error, free_mounting_width {:0.3f} is too big compare to cube_width {:0.3f} and gear_hollow_radius {:0.3f}".format(c['free_mounting_width'], c['cube_width'], gear_hollow_radius)) + six.print_(("ERR215: Error, free_mounting_width {:0.3f} is too big compare to cube_width {:0.3f} and gear_hollow_radius {:0.3f}".format(c['free_mounting_width'], c['cube_width'], gear_hollow_radius))) sys.exit(2) ### crest_hollow #crest_hollow_leg_nb # possible values: 1(filled), 2(end-legs only), 3, 4 ... if(c['crest_hollow_leg_nb']<1): - print("ERR220: Error, crest_hollow_leg_nb {:d} must be bigger or equal to 1".format(c['crest_hollow_leg_nb'])) + six.print_(("ERR220: Error, crest_hollow_leg_nb {:d} must be bigger or equal to 1".format(c['crest_hollow_leg_nb']))) sys.exit(2) #end_leg_width if(c['end_leg_width']0.7*2*math.pi*gear_hollow_radius*gear_portion_angle/c['crest_hollow_leg_nb']): - print("ERR228: Error, end_leg_width {:0.3f} is too big compare to gear_hollow_radius {:0.3f}, gear_portion_angle {:0.3f} and crest_hollow_leg_nb {:d}".format(c['end_leg_width'], gear_hollow_radius, gear_portion_angle, c['crest_hollow_leg_nb'])) + six.print_(("ERR228: Error, end_leg_width {:0.3f} is too big compare to gear_hollow_radius {:0.3f}, gear_portion_angle {:0.3f} and crest_hollow_leg_nb {:d}".format(c['end_leg_width'], gear_hollow_radius, gear_portion_angle, c['crest_hollow_leg_nb']))) sys.exit(2) #middle_leg_width if(c['middle_leg_width']==0): c['middle_leg_width'] = c['end_leg_width'] if(c['middle_leg_width']0.7*2*math.pi*gear_hollow_radius*gear_portion_angle/c['crest_hollow_leg_nb']): - print("ERR235: Error, middle_leg_width {:0.3f} is too big compare to gear_hollow_radius {:0.3f}, gear_portion_angle {:0.3f} and crest_hollow_leg_nb {:d}".format(c['middle_leg_width'], gear_hollow_radius, gear_portion_angle, c['crest_hollow_leg_nb'])) + six.print_(("ERR235: Error, middle_leg_width {:0.3f} is too big compare to gear_hollow_radius {:0.3f}, gear_portion_angle {:0.3f} and crest_hollow_leg_nb {:d}".format(c['middle_leg_width'], gear_hollow_radius, gear_portion_angle, c['crest_hollow_leg_nb']))) sys.exit(2) #crest_hollow_external_diameter c['crest_hollow_external_radius'] = c['crest_hollow_external_diameter']/2.0 if(c['crest_hollow_external_radius']==0): c['crest_hollow_external_radius'] = gear_hollow_radius - 1.5*c['gear_module'] if(c['crest_hollow_external_radius']>gear_hollow_radius): - print("ERR244: Error, crest_hollow_external_radius {:0.3f} is too big compare to gear_hollow_radius {:0.3f}".format(c['crest_hollow_external_radius'], gear_hollow_radius)) + six.print_(("ERR244: Error, crest_hollow_external_radius {:0.3f} is too big compare to gear_hollow_radius {:0.3f}".format(c['crest_hollow_external_radius'], gear_hollow_radius))) sys.exit(2) #crest_hollow_internal_diameter c['crest_hollow_internal_radius'] = c['crest_hollow_internal_diameter']/2.0 @@ -208,16 +209,16 @@ def crest_constraint_check(c): if(c['crest_hollow_internal_radius']==0): c['crest_hollow_internal_radius'] = minimal_crest_hollow_internal_radius if(c['crest_hollow_internal_radius']gear_hollow_radius): - print("ERR260: Error, floor_width {:0.3f} is too big compare to top_thickness {:0.3f}, height_margin {:0.3f}, axle_diameter {:0.3f} and gear_hollow_radius {:0.3f}".format(c['floor_width'], c['top_thickness'], c['height_margin'], c['axle_diameter'], gear_hollow_radius)) + six.print_(("ERR260: Error, floor_width {:0.3f} is too big compare to top_thickness {:0.3f}, height_margin {:0.3f}, axle_diameter {:0.3f} and gear_hollow_radius {:0.3f}".format(c['floor_width'], c['top_thickness'], c['height_margin'], c['axle_diameter'], gear_hollow_radius))) sys.exit(2) #crest_hollow_smoothing_radius max_leg_width = max(c['end_leg_width'], c['middle_leg_width']) @@ -225,35 +226,35 @@ def crest_constraint_check(c): if(c['crest_hollow_smoothing_radius']==0): c['crest_hollow_smoothing_radius'] = min(0.5*maximal_crest_hollow_smoothing_radius, 0.2*abs(c['crest_hollow_external_radius']-c['crest_hollow_internal_radius'])) if(c['crest_hollow_smoothing_radius']maximal_crest_hollow_smoothing_radius): - print("ERR270: Error, crest_hollow_smoothing_radius {:0.3f} must be smaller than maximal_crest_hollow_smoothing_radius {:0.3f}".format(c['crest_hollow_smoothing_radius'], maximal_crest_hollow_smoothing_radius)) + six.print_(("ERR270: Error, crest_hollow_smoothing_radius {:0.3f} must be smaller than maximal_crest_hollow_smoothing_radius {:0.3f}".format(c['crest_hollow_smoothing_radius'], maximal_crest_hollow_smoothing_radius))) sys.exit(2) if(c['crest_hollow_external_radius']gear_hollow_radius): - print("ERR282: Error, fastening_hole_position {:0.3f} or fastening_hole_radius {:0.3f} are too big compare to crest_hollow_external_radius {:0.3f} and gear_hollow_radius {:0.3f}".format(c['fastening_hole_position'], c['fastening_hole_radius'], c['crest_hollow_external_radius'], gear_hollow_radius)) + six.print_(("ERR282: Error, fastening_hole_position {:0.3f} or fastening_hole_radius {:0.3f} are too big compare to crest_hollow_external_radius {:0.3f} and gear_hollow_radius {:0.3f}".format(c['fastening_hole_position'], c['fastening_hole_radius'], c['crest_hollow_external_radius'], gear_hollow_radius))) sys.exit(2) #centring_hole_diameter c['centring_hole_radius'] = c['centring_hole_diameter']/2.0 #centring_hole_distance if(c['centring_hole_distance']<2.1*c['centring_hole_radius']): - print("ERR288: Error, centring_hole_distance {:0.3f} is too small compare to centring_hole_radius {:0.3f}".format(c['centring_hole_distance'], c['centring_hole_radius'])) + six.print_(("ERR288: Error, centring_hole_distance {:0.3f} is too small compare to centring_hole_radius {:0.3f}".format(c['centring_hole_distance'], c['centring_hole_radius']))) sys.exit(2) #centring_hole_position if(c['crest_hollow_external_radius'] + c['centring_hole_position'] + c['centring_hole_radius']>gear_hollow_radius): - print("ERR292: Error, centring_hole_position {:0.3f} or centring_hole_radius {:0.3f} are too big compare to crest_hollow_external_radius {:0.3f} and gear_hollow_radius {:0.3f}".format(c['centring_hole_position'], c['centring_hole_radius'], c['crest_hollow_external_radius'], gear_hollow_radius)) + six.print_(("ERR292: Error, centring_hole_position {:0.3f} or centring_hole_radius {:0.3f} are too big compare to crest_hollow_external_radius {:0.3f} and gear_hollow_radius {:0.3f}".format(c['centring_hole_position'], c['centring_hole_radius'], c['crest_hollow_external_radius'], gear_hollow_radius))) sys.exit(2) ## part thickness #crest_thickness if(c['crest_thickness']radian_epsilon): - print("ERR335: Error, extremities of the gear_profile_B have different y-coordiante {:0.3f} {:0.3f}".format(gear_profile_B[0][1], gear_profile_B[-1][-1])) + six.print_(("ERR335: Error, extremities of the gear_profile_B have different y-coordiante {:0.3f} {:0.3f}".format(gear_profile_B[0][1], gear_profile_B[-1][-1]))) sys.exit(2) # gear_profile extremity angle crest_gear_angle = math.atan2(gear_profile_B[0][1]-cy, gear_profile_B[0][0]-cx) @@ -370,7 +371,7 @@ def crest_2d_construction(c): ia1 = in1_angles[i] ia2 = in2_angles[i] if((ea2-ea1)<2.1*smoothing_ex_half_angle): - print("ERR419: Error, crest_hollow_smoothing_radius {:0.3f} or crest_hollow_leg_nb {:d} are too big".format(chsr, chln)) + six.print_(("ERR419: Error, crest_hollow_smoothing_radius {:0.3f} or crest_hollow_leg_nb {:d} are too big".format(chsr, chln))) sys.exit(2) hollow = [] hollow.append((cx+cher*math.cos(ea1), cy+cher*math.sin(ea1), chsr)) diff --git a/cnc25d/cross_cube.py b/cnc25d/cross_cube.py index c945a19..41b4109 100644 --- a/cnc25d/cross_cube.py +++ b/cnc25d/cross_cube.py @@ -29,7 +29,7 @@ # header for Python / FreeCAD compatibility ################################################################ -import cnc25d_api +from . import cnc25d_api cnc25d_api.importing_freecad() #print("FreeCAD.Version:", FreeCAD.Version()) @@ -52,8 +52,8 @@ #import svgwrite #from dxfwrite import DXFEngine # cnc25d -import cross_cube_sub -import crest +from . import cross_cube_sub +from . import crest ################################################################ # cross_cube constraint_constructor diff --git a/cnc25d/cross_cube_sub.py b/cnc25d/cross_cube_sub.py index 485448f..d7c3793 100644 --- a/cnc25d/cross_cube_sub.py +++ b/cnc25d/cross_cube_sub.py @@ -30,7 +30,8 @@ # header for Python / FreeCAD compatibility ################################################################ -import cnc25d_api +from . import cnc25d_api +import six cnc25d_api.importing_freecad() #print("FreeCAD.Version:", FreeCAD.Version()) @@ -167,30 +168,30 @@ def cross_cube_sub_face_check(ai_constraints): # axle_diameter cc_c['axle_radius'] = cc_c['axle_diameter']/2.0 if(cc_c['axle_radius'](cc_c['inter_axle_length']+2*cc_c['axle_radius']+2*cc_c['height_margin'])/4.0): - print("ERR235: top_thickness {:0.3f} is too small compare to inter_axle_length {:0.3}, axle_radius {:0.3}, height_margin {:0.3}".format(cc_c['top_thickness'], cc_c['inter_axle_length'], cc_c['axle_radius'], cc_c['height_margin'])) + six.print_(("ERR235: top_thickness {:0.3f} is too small compare to inter_axle_length {:0.3}, axle_radius {:0.3}, height_margin {:0.3}".format(cc_c['top_thickness'], cc_c['inter_axle_length'], cc_c['axle_radius'], cc_c['height_margin']))) sys.exit(2) cc_c['cube_height'] = cc_c['inter_axle_length'] + 2*cc_c['axle_radius'] + 2*cc_c['height_margin'] + 2*cc_c['top_thickness'] ## width # cube_width if(cc_c['cube_width']<3*cc_c['axle_radius']): - print("ERR239: Error, cube_width {:0.3f} is too small compare to axle_radius {:0.3f}".format(cc_c['cube_width'], cc_c['axle_radius'])) + six.print_(("ERR239: Error, cube_width {:0.3f} is too small compare to axle_radius {:0.3f}".format(cc_c['cube_width'], cc_c['axle_radius']))) sys.exit(2) # face_A1_thickness, face_A2_thickness, face_B1_thickness, face_B2_thickness face_thickness = [cc_c['face_A1_thickness'], cc_c['face_A2_thickness'], cc_c['face_B1_thickness'], cc_c['face_B2_thickness']] @@ -200,13 +201,13 @@ def cross_cube_sub_face_check(ai_constraints): if(face_thickness[i]==0): face_thickness[i] = cc_c['top_thickness'] if(face_thickness[i]<2*cc_c['cross_cube_cnc_router_bit_radius']): - print("ERR244: Error, face_thickness[{:d}] {:0.3f} is too small compare to cross_cube_cnc_router_bit_radius {:0.3f}".format(i, face_thickness[i], cc_c['cross_cube_cnc_router_bit_radius'])) + six.print_(("ERR244: Error, face_thickness[{:d}] {:0.3f} is too small compare to cross_cube_cnc_router_bit_radius {:0.3f}".format(i, face_thickness[i], cc_c['cross_cube_cnc_router_bit_radius']))) sys.exit(2) if(face_thickness[i]>cc_c['cube_width']/2.0-cc_c['axle_radius']): - print("ERR247: Error, face_thickness[{:d}] {:0.3f} is too big compare to cube_width {:0.3f} and axle_radius {:0.3f}".format(i, face_thickness[i], cc_c['cube_width'], cc_c['axle_radius'])) + six.print_(("ERR247: Error, face_thickness[{:d}] {:0.3f} is too big compare to cube_width {:0.3f} and axle_radius {:0.3f}".format(i, face_thickness[i], cc_c['cube_width'], cc_c['axle_radius']))) sys.exit(2) if(face_thickness[i]>cc_c['cube_width']/6.0): - print("ERR250: Error, face_thickness[{:d}] {:0.3f} is too big compare to cube_width {:0.3f}".format(i, face_thickness[i], cc_c['cube_width'])) + six.print_(("ERR250: Error, face_thickness[{:d}] {:0.3f} is too big compare to cube_width {:0.3f}".format(i, face_thickness[i], cc_c['cube_width']))) sys.exit(2) cc_c['face_A1_thickness'] = face_thickness[0] cc_c['face_A2_thickness'] = face_thickness[1] @@ -219,61 +220,61 @@ def cross_cube_sub_face_check(ai_constraints): if(cc_c['face_rod_hole_radius']>0): # face_rod_hole_h_position if(cc_c['face_rod_hole_h_position']cc_c['cube_width']/2.0-cc_c['axle_radius']): - print("ERR261: Error, face_rod_hole_h_position {:0.3f} is too big compare to max_face_thickness {:0.3f}, face_rod_hole_radius {:0.3f}, cube_width {:0.3f}, axle_radius {:0.3f}".format(cc_c['face_rod_hole_h_position'], cc_c['max_face_thickness'], cc_c['face_rod_hole_radius'], cc_c['cube_width'], cc_c['axle_radius'])) + six.print_(("ERR261: Error, face_rod_hole_h_position {:0.3f} is too big compare to max_face_thickness {:0.3f}, face_rod_hole_radius {:0.3f}, cube_width {:0.3f}, axle_radius {:0.3f}".format(cc_c['face_rod_hole_h_position'], cc_c['max_face_thickness'], cc_c['face_rod_hole_radius'], cc_c['cube_width'], cc_c['axle_radius']))) sys.exit(2) # face_rod_hole_v_distance if(cc_c['face_rod_hole_v_distance']<2*cc_c['face_rod_hole_radius']): - print("ERR264: Error, face_rod_hole_v_distance {:0.3f} must be bigger than face_rod_hole_diameter {:0.3f}".format(cc_c['face_rod_hole_v_distance'], 2*cc_c['face_rod_hole_radius'])) + six.print_(("ERR264: Error, face_rod_hole_v_distance {:0.3f} must be bigger than face_rod_hole_diameter {:0.3f}".format(cc_c['face_rod_hole_v_distance'], 2*cc_c['face_rod_hole_radius']))) sys.exit(2) if(cc_c['face_rod_hole_v_position']+cc_c['face_rod_hole_v_distance']+cc_c['face_rod_hole_radius']>cc_c['height_margin']+cc_c['inter_axle_length']): - print("ERR296: Error, face_rod_hole_v_distance {:0.3f} is too big compare to face_rod_hole_v_position {:0.3f}, face_rod_hole_radius {:0.3f}, height_margin {:0.3f} and inter_axle_length {:0.3f}".format(cc_c['face_rod_hole_v_distance'], cc_c['face_rod_hole_v_position'], cc_c['face_rod_hole_radius'], cc_c['height_margin'], cc_c['inter_axle_length'])) + six.print_(("ERR296: Error, face_rod_hole_v_distance {:0.3f} is too big compare to face_rod_hole_v_position {:0.3f}, face_rod_hole_radius {:0.3f}, height_margin {:0.3f} and inter_axle_length {:0.3f}".format(cc_c['face_rod_hole_v_distance'], cc_c['face_rod_hole_v_position'], cc_c['face_rod_hole_radius'], cc_c['height_margin'], cc_c['inter_axle_length']))) sys.exit(2) # face_rod_hole_v_position if(cc_c['face_rod_hole_v_position']cc_c['height_margin']): - print("ERR267: Error, face_rod_hole_v_position {:0.3f} is too big compare to face_rod_hole_radius {:0.3f} and height_margin {:0.3f}".format(cc_c['face_rod_hole_v_position'], cc_c['face_rod_hole_radius'], cc_c['height_margin'])) + six.print_(("ERR267: Error, face_rod_hole_v_position {:0.3f} is too big compare to face_rod_hole_radius {:0.3f} and height_margin {:0.3f}".format(cc_c['face_rod_hole_v_position'], cc_c['face_rod_hole_radius'], cc_c['height_margin']))) sys.exit(2) ## top ### hollow ## face hollow # face_hollow_leg_nb if(not(cc_c['face_hollow_leg_nb'] in [1, 4, 8])): - print("ERR281: Error, face_hollow_leg_nb {:d} accepts only the values: 1, 4 or 8".format(cc_c['face_hollow_leg_nb'])) + six.print_(("ERR281: Error, face_hollow_leg_nb {:d} accepts only the values: 1, 4 or 8".format(cc_c['face_hollow_leg_nb']))) sys.exit(2) # face_hollow_border_width if(cc_c['face_hollow_border_width']==0): cc_c['face_hollow_border_width'] = cc_c['max_face_top_thickness'] if(cc_c['face_hollow_border_width']min(cc_c['cube_width']/5.0, cc_c['cube_height']/4.0)/3.0): - print("ERR369: Error, cross_cube_extra_cut_thickness {:0.3} absolute value is too big compare to cube_width {:0.3f} and cube_height {:0.3f}".format(cc_c['cross_cube_extra_cut_thickness'], cc_c['cube_width'], cc_c['cube_height'])) + six.print_(("ERR369: Error, cross_cube_extra_cut_thickness {:0.3} absolute value is too big compare to cube_width {:0.3f} and cube_height {:0.3f}".format(cc_c['cross_cube_extra_cut_thickness'], cc_c['cube_width'], cc_c['cube_height']))) sys.exit(2) # return return(cc_c) @@ -294,55 +295,55 @@ def cross_cube_sub_top_check(ai_constraints): if(cc_c['top_rod_hole_radius']>0): # top_rod_hole_h_position if(cc_c['top_rod_hole_h_position']cc_c['cube_width']/2.0-cc_c['axle_radius']): - print("ERR276: Error, top_rod_hole_h_position {:0.3f} is too big compare to max_face_thickness {:0.3f}, top_rod_hole_radius {:0.3f}, cube_width {:0.3f} and axle_radius {:0.3f}".format(cc_c['top_rod_hole_h_position'], cc_c['max_face_thickness'], cc_c['top_rod_hole_radius'], cc_c['cube_width'], cc_c['axle_radius'])) + six.print_(("ERR276: Error, top_rod_hole_h_position {:0.3f} is too big compare to max_face_thickness {:0.3f}, top_rod_hole_radius {:0.3f}, cube_width {:0.3f} and axle_radius {:0.3f}".format(cc_c['top_rod_hole_h_position'], cc_c['max_face_thickness'], cc_c['top_rod_hole_radius'], cc_c['cube_width'], cc_c['axle_radius']))) sys.exit(2) ## top hollow # top_hollow_leg_nb if(not(cc_c['top_hollow_leg_nb'] in [0, 1, 4, 8])): - print("ERR325: Error, top_hollow_leg_nb {:d} accepts only the values: 0, 1, 4, 8".format(cc_c['top_hollow_leg_nb'])) + six.print_(("ERR325: Error, top_hollow_leg_nb {:d} accepts only the values: 0, 1, 4, 8".format(cc_c['top_hollow_leg_nb']))) sys.exit(2) # top_hollow_border_width if(cc_c['top_hollow_border_width']==0): cc_c['top_hollow_border_width'] = cc_c['max_face_thickness'] if(cc_c['top_hollow_border_width'](cc_c['axle_length']-cc_c['cube_width'])/2.0): - print("ERR363: Error, spacer_length {:0.3f} is too big compare to axle_length {:0.3f} and cube_width {:0.3f}".format(cc_c['spacer_length'], cc_c['axle_length'], cc_c['cube_width'])) + six.print_(("ERR363: Error, spacer_length {:0.3f} is too big compare to axle_length {:0.3f} and cube_width {:0.3f}".format(cc_c['spacer_length'], cc_c['axle_length'], cc_c['cube_width']))) sys.exit(2) # return return(cc_c) diff --git a/cnc25d/design_frontend.py b/cnc25d/design_frontend.py index badae5f..0ab5636 100644 --- a/cnc25d/design_frontend.py +++ b/cnc25d/design_frontend.py @@ -43,6 +43,7 @@ import math import sys import re +import six #import argparse #from datetime import datetime #import os, errno @@ -75,7 +76,7 @@ def check(constraint_dict={}, error_id="ERR000", error_msg='', constraint_dict_n msg_introduction = "Warning on" #print("ERR073: Error on {:s} with:".format(error_msg)) error_msg_without_dict = re.sub("'\]", " ", re.sub("{:s}\['".format(constraint_dict_name), " ", error_msg)) - print("{:s}: {:s} {:s} with:".format(error_id, msg_introduction, error_msg_without_dict)) + six.print_(("{:s}: {:s} {:s} with:".format(error_id, msg_introduction, error_msg_without_dict))) var_list = re.findall("{:s}\['\w+'\]".format(constraint_dict_name), error_msg) #print("dbg075: var_list:", var_list) for d_item in var_list: @@ -83,7 +84,7 @@ def check(constraint_dict={}, error_id="ERR000", error_msg='', constraint_dict_n #d_key = re.sub("^.*\['(\w+)'\]$", "\1", d_item) #print("dbg078: d_key:", d_key) d_val = constraint_dict[d_key] - print("{:s}['{:s}'] = {:s}".format(constraint_dict_name, d_key, str(d_val))) + six.print_(("{:s}['{:s}'] = {:s}".format(constraint_dict_name, d_key, str(d_val)))) if(not warning_nerror): sys.exit(2) else: diff --git a/cnc25d/design_help.py b/cnc25d/design_help.py index 5fea92a..223a51c 100644 --- a/cnc25d/design_help.py +++ b/cnc25d/design_help.py @@ -44,6 +44,7 @@ import sys, argparse #from datetime import datetime import os, errno +import six #import re #import Tkinter # to display the outline in a small GUI # FreeCAD @@ -72,7 +73,7 @@ def mkdir_p(ai_directory): if(ai_directory!=''): #print("dbg448: ai_directory:", ai_directory) # mkdir -p directory if needed - print("dbg450: try to create the output directory: {:s}".format(ai_directory)) + six.print_(("dbg450: try to create the output directory: {:s}".format(ai_directory))) try: os.makedirs(ai_directory) r_status = 0 diff --git a/cnc25d/design_output.py b/cnc25d/design_output.py index 024617f..7a82309 100644 --- a/cnc25d/design_output.py +++ b/cnc25d/design_output.py @@ -29,7 +29,8 @@ # header for Python / FreeCAD compatibility ################################################################ -import importing_freecad +from . import importing_freecad +import six importing_freecad.importing_freecad() #print("FreeCAD.Version:", FreeCAD.Version()) @@ -54,11 +55,11 @@ #import svgwrite #from dxfwrite import DXFEngine # cnc25d -import outline_backends -import export_2d -import design_help -import cnc_outline -import positioning +from . import outline_backends +from . import export_2d +from . import design_help +from . import cnc_outline +from . import positioning ################################################################ @@ -114,21 +115,21 @@ def generate_output_file(ai_figure, ai_output_filename, ai_height, ai_info_txt=' outline_backends.write_figure_in_svg(ai_figure, ai_output_filename) # FreeCAD elif(re.search('\.brep$', ai_output_filename)): - print("Generate with FreeCAD the BRep file {:s}".format(ai_output_filename)) + six.print_(("Generate with FreeCAD the BRep file {:s}".format(ai_output_filename))) freecad_part = outline_backends.figure_to_freecad_25d_part(ai_figure, ai_height) freecad_part.exportBrep("{:s}".format(ai_output_filename)) - print("Generate with FreeCAD the DXF file {:s}.dxf".format(ai_output_filename)) + six.print_(("Generate with FreeCAD the DXF file {:s}.dxf".format(ai_output_filename))) # slice freecad_part in the XY plan at a height of ai_height/2 export_2d.export_to_dxf(freecad_part, Base.Vector(0,0,1), ai_height/2, "{:s}.dxf".format(ai_output_filename)) elif(re.search('\.stl$', ai_output_filename)): - print("Generate with FreeCAD the STL file {:s}".format(ai_output_filename)) + six.print_(("Generate with FreeCAD the STL file {:s}".format(ai_output_filename))) freecad_part = outline_backends.figure_to_freecad_25d_part(ai_figure, ai_height) freecad_part.exportStl("{:s}".format(ai_output_filename)) - print("Generate with FreeCAD the DXF file {:s}.dxf".format(ai_output_filename)) + six.print_(("Generate with FreeCAD the DXF file {:s}.dxf".format(ai_output_filename))) # slice freecad_part in the XY plan at a height of ai_height/2 export_2d.export_to_dxf(freecad_part, Base.Vector(0,0,1), ai_height/2, "{:s}.dxf".format(ai_output_filename)) else: - print("ERR124: Error: the suffix of the filename {:s} is unknown. Try with suffix: .dxf, .svg, .brep or .stl".format(ai_output_filename)) + six.print_(("ERR124: Error: the suffix of the filename {:s} is unknown. Try with suffix: .dxf, .svg, .brep or .stl".format(ai_output_filename))) sys.exit(2) # info_txt #if(ai_info_txt!=''): @@ -147,15 +148,15 @@ def freecad_object_output_file(ai_freecad_object, ai_output_filename, ai_brep=Tr """ if(ai_brep): brep_output_filename = "{:s}.brep".format(ai_output_filename) - print("Generate with FreeCAD the BRep file {:s}".format(brep_output_filename)) + six.print_(("Generate with FreeCAD the BRep file {:s}".format(brep_output_filename))) ai_freecad_object.exportBrep(brep_output_filename) if(ai_stl): stl_output_filename = "{:s}.stl".format(ai_output_filename) - print("Generate with FreeCAD the STL file {:s}".format(stl_output_filename)) + six.print_(("Generate with FreeCAD the STL file {:s}".format(stl_output_filename))) ai_freecad_object.exportStl(stl_output_filename) if(len(ai_slice_xyz)>0): if(len(ai_slice_xyz)!=9): - print("ERR150: Error, len(ai_slice_xyz) {:d} must be 9".format(len(ai_slice_xyz))) + six.print_(("ERR150: Error, len(ai_slice_xyz) {:d} must be 9".format(len(ai_slice_xyz)))) sys.exit(2) size_x = ai_slice_xyz[0] size_y = ai_slice_xyz[1] @@ -167,7 +168,7 @@ def freecad_object_output_file(ai_freecad_object, ai_output_filename, ai_brep=Tr slice_y = ai_slice_xyz[7] slice_z = ai_slice_xyz[8] dxf_output_filename = "{:s}_xyz_slices.dxf".format(ai_output_filename) - print("Slice with FreeCAD the 3D into the DXF file {:s}".format(dxf_output_filename)) + six.print_(("Slice with FreeCAD the 3D into the DXF file {:s}".format(dxf_output_filename))) #print("dbg161: zero_x {:0.3f} zero_y {:0.3f} zero_z {:0.3f}".format(zero_x, zero_y, zero_z)) ai_freecad_object.translate(Base.Vector(-1*zero_x, -1*zero_y, -1*zero_z)) export_2d.export_xyz_to_dxf(ai_freecad_object, size_x, size_y, size_z, slice_x, slice_y, slice_z, dxf_output_filename) @@ -176,7 +177,7 @@ def freecad_object_output_file(ai_freecad_object, ai_output_filename, ai_brep=Tr def generate_3d_assembly_output_file(ai_3d_conf, ai_output_filename, ai_brep=True, ai_stl=False, ai_slice_xyz=[]): """ implement the swith --output_file_basename for 3D assembly """ - print("Compute with FreeCAD the 3D assembly {:s}".format(ai_output_filename)) + six.print_(("Compute with FreeCAD the 3D assembly {:s}".format(ai_output_filename))) fc_assembly = figures_to_freecad_assembly(ai_3d_conf) freecad_object_output_file(fc_assembly, ai_output_filename, ai_brep, ai_stl, ai_slice_xyz) return(0) @@ -237,7 +238,7 @@ def figures_to_freecad_assembly(ai_figure_assembly): fc_obj = [] for i in range(obj_nb): if(len(ai_figure_assembly[i])!=11): - print("ERR219: Error len of ai_figure_assembly {:d} must be 11".format(len(ai_figure_assembly[i]))) + six.print_(("ERR219: Error len of ai_figure_assembly {:d} must be 11".format(len(ai_figure_assembly[i])))) sys.exit(2) (part_figure, zero_x, zero_y, size_x, size_y, size_z, flip, orientation, translate_x, translate_y, translate_z) = ai_figure_assembly[i] part_figure_zero = rotate_and_translate_figure(part_figure, 0, 0, 0, -1*zero_x, -1*zero_y) diff --git a/cnc25d/display_backend.py b/cnc25d/display_backend.py index 0932d52..c6b0d80 100644 --- a/cnc25d/display_backend.py +++ b/cnc25d/display_backend.py @@ -33,10 +33,11 @@ import math import sys, argparse -import Tkinter +from six.moves import tkinter #import tkMessageBox import matplotlib.pyplot -import design_help # just for get_effective_args() +from . import design_help # just for get_effective_args() +import six ################################################################ # global variable @@ -69,7 +70,7 @@ def find_outline_extremum(ai_outline_list): first_point_x=first_outline[0] first_point_y=first_outline[1] else: - print("ERR305: Error, the outline type is unknow: {:s}".format(first_outline_type)) + six.print_(("ERR305: Error, the outline type is unknow: {:s}".format(first_outline_type))) sys.exit(2) min_x=first_point_x max_x=first_point_x @@ -291,11 +292,11 @@ def action_button_check_event(self, event): """ This function is only used for debug It has no utility for the Two_Canvas class """ - print("dbg141: event:", event) - print("dbg142: event.time:", event.time) - print("dbg143: event.type:", event.type) - print("dbg144: event.widget:", event.widget) - print("dbg145: event.keysym:", event.keysym) + six.print_(("dbg141: event:", event)) + six.print_(("dbg142: event.time:", event.time)) + six.print_(("dbg143: event.type:", event.type)) + six.print_(("dbg144: event.widget:", event.widget)) + six.print_(("dbg145: event.keysym:", event.keysym)) def action_canvas_a_mouse_button_press(self, event): """ Start of the zoom area selection @@ -366,8 +367,8 @@ def action_canvas_b_mouse_button_release(self, event): if(length_measurement>0): angle_measurement = math.atan2((p2y-p1y)/length_measurement, (p2x-p1x)/length_measurement) self.measurement_id += 1 - print("Info: measurement {:2d} : lenght: {:0.3f} angle: {:0.3f}".format(self.measurement_id, length_measurement, angle_measurement)) - print("P1x: {:0.2f} P1y: {:0.2f} P2x: {:0.2f} P2y: {:0.2f}".format(p1x, p1y, p2x, p2y)) + six.print_(("Info: measurement {:2d} : lenght: {:0.3f} angle: {:0.3f}".format(self.measurement_id, length_measurement, angle_measurement))) + six.print_(("P1x: {:0.2f} P1y: {:0.2f} P2x: {:0.2f} P2y: {:0.2f}".format(p1x, p1y, p2x, p2y))) def simulation_step(self): """ Time simulation main function @@ -414,7 +415,7 @@ def apply_canvas_graphic_function(self): if(self.canvas_graphic_function!=None): all_graphics = self.canvas_graphic_function(self.rotation_direction, self.angle_position) # - self.canvas_a.delete(Tkinter.ALL) + self.canvas_a.delete(tkinter.ALL) # uncomment if you want to scale outline depending on the angle_position #self.outline_extremum = find_outline_extremum(all_graphics) canvas_a_size = (canvas_a_width, canvas_a_height, tkinter_canvas_margin_x, tkinter_canvas_margin_y) @@ -427,7 +428,7 @@ def apply_canvas_graphic_function(self): if(self.crop_limit==(0,0,0,0)): self.crop_limit=(self.outline_extremum[0], self.outline_extremum[1], (self.outline_extremum[0]+self.outline_extremum[2])/2, (self.outline_extremum[1]+self.outline_extremum[3])/2) # - self.canvas_b.delete(Tkinter.ALL) + self.canvas_b.delete(tkinter.ALL) crop_graphics = crop_outline(all_graphics, self.crop_limit) #print("dbg857: len(crop_graphics):", len(crop_graphics)) canvas_b_size = (canvas_b_width, canvas_b_height, 2, 2) @@ -465,15 +466,15 @@ def create_zoom_frame(self): """ Define the zoom window """ #print("dbg554: create_zoom_frame") - self.frame_b = Tkinter.Toplevel(self.frame_a) + self.frame_b = tkinter.Toplevel(self.frame_a) #self.frame_b.grid(column=0, row=0, sticky=Tkinter.N+Tkinter.E+Tkinter.S+Tkinter.W) # Toplevel doesn't have grid method ! #self.frame_b.pack(fill=Tkinter.BOTH, expand=1) self.frame_b.title("cnc25d display backend details") - self.canvas_b = Tkinter.Canvas(self.frame_b, width=initial_tkinter_canvas_width, height=initial_tkinter_canvas_height) + self.canvas_b = tkinter.Canvas(self.frame_b, width=initial_tkinter_canvas_width, height=initial_tkinter_canvas_height) #self.canvas_b.grid(column=0, row=0, sticky=Tkinter.N+Tkinter.E+Tkinter.S+Tkinter.W) #self.canvas_b.columnconfigure(0, weight=1) #self.canvas_b.rowconfigure(0, weight=1) - self.canvas_b.pack(fill=Tkinter.BOTH, expand=1) # with Toplevel parent, it seems you need to use pack to resisze the canvas ! + self.canvas_b.pack(fill=tkinter.BOTH, expand=1) # with Toplevel parent, it seems you need to use pack to resisze the canvas ! self.canvas_b.bind("", self.action_canvas_b_mouse_button_press) self.canvas_b.bind("", self.action_canvas_b_mouse_button_motion) self.canvas_b.bind("", self.action_canvas_b_mouse_button_release) @@ -510,10 +511,10 @@ def create_parameter_frame(self): """ Define the parameter window """ #print("dbg414: create_parameter_frame") - self.frame_c = Tkinter.Toplevel(self.frame_a) + self.frame_c = tkinter.Toplevel(self.frame_a) self.frame_c.title("parameter info") - self.parameter_message = Tkinter.Message(self.frame_c, textvariable=self.parameter_content) - self.parameter_message.grid(sticky=Tkinter.N+Tkinter.E+Tkinter.S+Tkinter.W) + self.parameter_message = tkinter.Message(self.frame_c, textvariable=self.parameter_content) + self.parameter_message.grid(sticky=tkinter.N+tkinter.E+tkinter.S+tkinter.W) self.frame_c.protocol("WM_DELETE_WINDOW", self.hide_parameter_frame) # change the behaviour of the window X button def hide_parameter_frame(self): @@ -561,7 +562,7 @@ def action_button_curve_graph(self, event): for j in range(curve_nb-1): check_len = len( self.curve_graphic_table[j+2][1]) if(check_len!=curve_table_len): - print("ERR586: Error in the curve_table {:d}! Its lenght {:d} does not match the reference length {:d}".format(j, check_len, curve_table_len)) + six.print_(("ERR586: Error in the curve_table {:d}! Its lenght {:d} does not match the reference length {:d}".format(j, check_len, curve_table_len))) x_increment = self.curve_graphic_table[0][2] abscissa_x = 0 for i in range(curve_table_len): @@ -604,105 +605,105 @@ def createWidgets(self): #self.frame_canvas.rowconfigure(0, weight=1) # #self.canvas_a = Tkinter.Canvas(self.frame_a, width=self.canvas_a_width, height=self.canvas_a_height) - self.canvas_a = Tkinter.Canvas(self.frame_a, width=initial_tkinter_canvas_width, height=initial_tkinter_canvas_height) + self.canvas_a = tkinter.Canvas(self.frame_a, width=initial_tkinter_canvas_width, height=initial_tkinter_canvas_height) #self.canvas_a.pack(fill=Tkinter.BOTH, expand=1) - self.canvas_a.grid(column=0, row=0, sticky=Tkinter.N+Tkinter.E+Tkinter.S+Tkinter.W) + self.canvas_a.grid(column=0, row=0, sticky=tkinter.N+tkinter.E+tkinter.S+tkinter.W) self.canvas_a.columnconfigure(0, weight=1) self.canvas_a.rowconfigure(0, weight=1) self.canvas_a.bind("", self.action_canvas_a_mouse_button_press) self.canvas_a.bind("", self.action_canvas_a_mouse_button_motion) self.canvas_a.bind("", self.action_canvas_a_mouse_button_release) # - self.frame_control = Tkinter.Frame(self.frame_a) + self.frame_control = tkinter.Frame(self.frame_a) #self.frame_control.pack(side=Tkinter.BOTTOM) - self.frame_control.grid(column=0, row=1, sticky=Tkinter.W + Tkinter.S) + self.frame_control.grid(column=0, row=1, sticky=tkinter.W + tkinter.S) # - self.frame_button_speed = Tkinter.Frame(self.frame_control) + self.frame_button_speed = tkinter.Frame(self.frame_control) self.frame_button_speed.grid(column=0, row=0) # - self.button_fast_backward = Tkinter.Button(self.frame_button_speed) + self.button_fast_backward = tkinter.Button(self.frame_button_speed) self.button_fast_backward["text"] = "<<-", self.button_fast_backward["command"] = self.action_button_fast_backward - self.button_fast_backward.pack(side=Tkinter.LEFT) + self.button_fast_backward.pack(side=tkinter.LEFT) # - self.button_slow_backward = Tkinter.Button(self.frame_button_speed) + self.button_slow_backward = tkinter.Button(self.frame_button_speed) self.button_slow_backward["text"] = "<-", self.button_slow_backward["command"] = self.action_button_slow_backward - self.button_slow_backward.pack(side=Tkinter.LEFT) + self.button_slow_backward.pack(side=tkinter.LEFT) # - self.button_step_backward = Tkinter.Button(self.frame_button_speed) + self.button_step_backward = tkinter.Button(self.frame_button_speed) self.button_step_backward["text"] = "<|", self.button_step_backward["command"] = self.action_button_step_backward - self.button_step_backward.pack(side=Tkinter.LEFT) + self.button_step_backward.pack(side=tkinter.LEFT) # - self.button_stop = Tkinter.Button(self.frame_button_speed) + self.button_stop = tkinter.Button(self.frame_button_speed) self.button_stop["foreground"] = "red" self.button_stop["text"] = "||", self.button_stop["command"] = self.action_button_stop - self.button_stop.pack(side=Tkinter.LEFT) + self.button_stop.pack(side=tkinter.LEFT) # - self.button_step_forward = Tkinter.Button(self.frame_button_speed) + self.button_step_forward = tkinter.Button(self.frame_button_speed) self.button_step_forward["text"] = "|>", self.button_step_forward["command"] = self.action_button_step_forward - self.button_step_forward.pack(side=Tkinter.LEFT) + self.button_step_forward.pack(side=tkinter.LEFT) # - self.button_slow_forward = Tkinter.Button(self.frame_button_speed) + self.button_slow_forward = tkinter.Button(self.frame_button_speed) self.button_slow_forward["text"] = "->", self.button_slow_forward["command"] = self.action_button_slow_forward - self.button_slow_forward.pack(side=Tkinter.LEFT) + self.button_slow_forward.pack(side=tkinter.LEFT) # - self.button_fast_forward = Tkinter.Button(self.frame_button_speed) + self.button_fast_forward = tkinter.Button(self.frame_button_speed) self.button_fast_forward["text"] = "->>", self.button_fast_forward["command"] = self.action_button_fast_forward - self.button_fast_forward.pack(side=Tkinter.LEFT) + self.button_fast_forward.pack(side=tkinter.LEFT) # - self.frame_label = Tkinter.Frame(self.frame_control) - self.frame_label.grid(column=0, row=1, sticky=Tkinter.W) + self.frame_label = tkinter.Frame(self.frame_control) + self.frame_label.grid(column=0, row=1, sticky=tkinter.W) # - self.label_angle = Tkinter.Label(self.frame_label) + self.label_angle = tkinter.Label(self.frame_label) self.label_angle["textvariable"] = self.label1_content #self.label_angle.pack(side=Tkinter.TOP) #self.label_angle.pack(anchor=Tkinter.NW) - self.label_angle.grid(column=0, row=0, sticky=Tkinter.W) + self.label_angle.grid(column=0, row=0, sticky=tkinter.W) # - self.label_angle_speed = Tkinter.Label(self.frame_label) + self.label_angle_speed = tkinter.Label(self.frame_label) self.label_angle_speed["textvariable"] = self.label2_content #self.label_angle_speed.pack(side=Tkinter.BOTTOM) #self.label_angle_speed.pack(anchor=Tkinter.SW) - self.label_angle_speed.grid(column=0, row=1, sticky=Tkinter.W) + self.label_angle_speed.grid(column=0, row=1, sticky=tkinter.W) # - self.frame_button_options = Tkinter.Frame(self.frame_control) - self.frame_button_options.grid(column=0, row=2, sticky=Tkinter.W+Tkinter.S) + self.frame_button_options = tkinter.Frame(self.frame_control) + self.frame_button_options.grid(column=0, row=2, sticky=tkinter.W+tkinter.S) # - self.button_zoom = Tkinter.Button(self.frame_button_options) + self.button_zoom = tkinter.Button(self.frame_button_options) self.button_zoom["text"] = "Zoom", self.button_zoom["command"] = self.action_button_zoom - self.button_zoom.pack(side=Tkinter.LEFT) + self.button_zoom.pack(side=tkinter.LEFT) # - self.button_overlay = Tkinter.Button(self.frame_button_options) + self.button_overlay = tkinter.Button(self.frame_button_options) self.button_overlay["text"] = "Overlay", self.button_overlay["command"] = self.action_button_overlay - self.button_overlay.pack(side=Tkinter.LEFT) + self.button_overlay.pack(side=tkinter.LEFT) # - self.button_parameter = Tkinter.Button(self.frame_button_options) + self.button_parameter = tkinter.Button(self.frame_button_options) self.button_parameter["text"] = "Parameters", self.button_parameter["command"] = self.action_button_parameters - self.button_parameter.pack(side=Tkinter.LEFT) + self.button_parameter.pack(side=tkinter.LEFT) # - self.button_graph = Tkinter.Button(self.frame_button_options) + self.button_graph = tkinter.Button(self.frame_button_options) self.button_graph["text"] = "Graph", #self.button_graph["command"] = lambda a=1: self.action_button_check_event(a) #self.button_graph.bind("", lambda event: self.action_button_check_event(event)) #self.button_graph.bind("", self.action_button_check_event) # the event argument is added by default self.button_graph.bind("", self.action_button_curve_graph) # the event argument is added by default - self.button_graph.pack(side=Tkinter.LEFT) + self.button_graph.pack(side=tkinter.LEFT) # - self.button_quit = Tkinter.Button(self.frame_button_options) + self.button_quit = tkinter.Button(self.frame_button_options) self.button_quit["text"] = "Quit", #self.button_quit["command"] = self.frame_a.quit #self.button_quit["command"] = self.tktop.destroy self.button_quit["command"] = self.quit_Two_Canvas - self.button_quit.pack(side=Tkinter.LEFT) + self.button_quit.pack(side=tkinter.LEFT) # ## second window with canvas_b self.create_zoom_frame() @@ -716,13 +717,13 @@ def __init__(self, winParent): """ Initiate the class Two_Canvas by creating the windows, initializing the class variables and starting the time simulation """ self.tktop = winParent # used to destroy the app when quit - self.frame_a = Tkinter.Frame(winParent) + self.frame_a = tkinter.Frame(winParent) winParent.title("cnc25d display backend main") #self.frame_a.pack() #winParent.grid(sticky=Tkinter.N+Tkinter.E+Tkinter.S+Tkinter.W) winParent.columnconfigure(0, weight=1) winParent.rowconfigure(0, weight=1) - self.frame_a.grid(sticky=Tkinter.N+Tkinter.E+Tkinter.S+Tkinter.W) + self.frame_a.grid(sticky=tkinter.N+tkinter.E+tkinter.S+tkinter.W) self.frame_a.columnconfigure(0, weight=1) self.frame_a.rowconfigure(0, weight=1) # @@ -731,11 +732,11 @@ def __init__(self, winParent): self.angle_position = 0 self.outline_extremum = (0,0,0,0) # - self.label1_content = Tkinter.StringVar() - self.label2_content = Tkinter.StringVar() + self.label1_content = tkinter.StringVar() + self.label2_content = tkinter.StringVar() self.set_label_content() # - self.parameter_content = Tkinter.StringVar() + self.parameter_content = tkinter.StringVar() # self.overlay = 0 self.canvas_graphic_function = None @@ -865,7 +866,7 @@ def two_canvas_class_test1(): ('plot1_title', test1_curve1, 'bo'), ('plot2_title', test1_curve2, 'r')) # - tk_root = Tkinter.Tk() + tk_root = tkinter.Tk() dut = Two_Canvas(tk_root) #dut = Two_Canvas() dut.add_canvas_graphic_function(test_canvas_graphic_1) @@ -909,7 +910,7 @@ def two_canvas_class_test2(): ('plot1_title', test1_curve1, 'bo'), ('plot2_title', test1_curve2, 'r')) # - tk_root = Tkinter.Tk() + tk_root = tkinter.Tk() dut = Two_Canvas(tk_root) dut.add_canvas_graphic_function(test_canvas_graphic_2) dut.add_parameter_info(test_parameter_info) diff --git a/cnc25d/draw_2d_frontend.py b/cnc25d/draw_2d_frontend.py index 31cda1d..cca64a9 100644 --- a/cnc25d/draw_2d_frontend.py +++ b/cnc25d/draw_2d_frontend.py @@ -49,8 +49,9 @@ #from datetime import datetime #import os, errno ## cnc25d -import small_geometry -import cnc_outline +from . import small_geometry +from . import cnc_outline +import six #import outline_backends #import export_2d @@ -65,10 +66,10 @@ def get_center(CX=0.0, CY=0.0, C=()): OCY = CY if(len(C)>0): if((CX!=0)or(CY!=0)): - print("ERR112: Error, CX {:0.3f} or CY {:0.3d} have been set simultaneously with C".format(CX, CY)) + six.print_(("ERR112: Error, CX {:0.3f} or CY {:0.3d} have been set simultaneously with C".format(CX, CY))) sys.exit(2) if(len(C)!=2): - print("ERR115: len(C) {:d} is not 2".format(len(C))) + six.print_(("ERR115: len(C) {:d} is not 2".format(len(C)))) sys.exit(2) OCX = C[0] OCY = C[1] @@ -82,7 +83,7 @@ def c_xy(d, a, CX=0.0, CY=0.0, C=()): """ # check distance if(d<0): - print("ERR104: Error, the polar coordinate distance d {:0.3f} is negative".format(d)) + six.print_(("ERR104: Error, the polar coordinate distance d {:0.3f} is negative".format(d))) sys.exit(2) # origin-center (OCX, OCY) = get_center(CX, CY, C) @@ -133,7 +134,7 @@ def add_StartPoint(self, CX=0.0, CY=0.0, C=(), rbr=0.0): rbr is the router_bit_radius to be applied on the StartPoint corner. """ if(self.ol!=[]): - print("ERR152: Error, StartPoint can not be added to the outline {:s} with {:d} segments".format(self.outline_id, len(self.ol))) + six.print_(("ERR152: Error, StartPoint can not be added to the outline {:s} with {:d} segments".format(self.outline_id, len(self.ol)))) sys.exit(2) (X, Y) = get_center(CX, CY, C) self.ol.append((X, Y, rbr)) @@ -144,7 +145,7 @@ def add_LineTo(self, CX=0.0, CY=0.0, C=(), rbr=0.0): rbr is the router_bit_radius to be applied on the new point corner. """ if(len(self.ol)<1): - print("ERR163: Error, line-segment can not be added to the outline {:s} with {:d} segments. Add StartPoint first.".format(self.outline_id, len(self.ol))) + six.print_(("ERR163: Error, line-segment can not be added to the outline {:s} with {:d} segments. Add StartPoint first.".format(self.outline_id, len(self.ol)))) sys.exit(2) (X, Y) = get_center(CX, CY, C) self.ol.append((X, Y, rbr)) @@ -155,7 +156,7 @@ def add_ArcThrTo(self, CX1=0.0, CY1=0.0, CX2=0.0, CY2=0.0, C1=(), C2=(), rbr=0.0 rbr is the router_bit_radius to be applied on the CX2,CY2 corner. """ if(len(self.ol)<1): - print("ERR174: Error, arc-segment can not be added to the outline {:s} with {:d} segments. Add StartPoint first.".format(self.outline_id, len(self.ol))) + six.print_(("ERR174: Error, arc-segment can not be added to the outline {:s} with {:d} segments. Add StartPoint first.".format(self.outline_id, len(self.ol)))) sys.exit(2) (X1, Y1) = get_center(CX1, CY1, C1) (X2, Y2) = get_center(CX2, CY2, C2) @@ -167,7 +168,7 @@ def add_ArcThrTo_radius_angles(self, R, a1, a2, CX=0.0, CY=0.0, C=(), rbr=0.0): rbr is the router_bit_radius to be applied on the CX2,CY2 corner. """ if(len(self.ol)<1): - print("ERR174: Error, arc-segment can not be added to the outline {:s} with {:d} segments. Add StartPoint first.".format(self.outline_id, len(self.ol))) + six.print_(("ERR174: Error, arc-segment can not be added to the outline {:s} with {:d} segments. Add StartPoint first.".format(self.outline_id, len(self.ol)))) sys.exit(2) (X1, Y1) = c_xy(R, a1, CX, CY, C) (X2, Y2) = c_xy(R, a2, CX, CY, C) @@ -184,7 +185,7 @@ def close_with_Line(self): Close the outline with a line-segment """ if(len(self.ol)<2): - print("ERR157: Error, line-segment can not be added to close the outline {:s} with {:d} segments. Add at least one segment first.".format(self.outline_id, len(self.ol))) + six.print_(("ERR157: Error, line-segment can not be added to close the outline {:s} with {:d} segments. Add at least one segment first.".format(self.outline_id, len(self.ol)))) sys.exit(2) X = self.ol[0][0] Y = self.ol[0][1] @@ -195,7 +196,7 @@ def close_with_ArcThr(self, CX1=0.0, CY1=0.0, C1=()): Close the outline with an arc-segment """ if(len(self.ol)<2): - print("ERR168: Error, arc-segment can not be added to close the outline {:s} with {:d} segments. Add at least one segment first.".format(self.outline_id, len(self.ol))) + six.print_(("ERR168: Error, arc-segment can not be added to close the outline {:s} with {:d} segments. Add at least one segment first.".format(self.outline_id, len(self.ol)))) sys.exit(2) (X1, Y1) = get_center(CX1, CY1, C1) X2 = self.ol[0][0] @@ -210,7 +211,7 @@ def close_insurance(self): radian_epsilon = math.pi/1000 # if((abs(self.ol[0][0]-self.ol[-1][-3])>radian_epsilon)or(abs(self.ol[0][1]-self.ol[-1][-2])>radian_epsilon)): - print("ERR206: Error, outline {:s} should be closed but is not closed: first point ({:0.3f}, {:0.3f}), last point ({:0.3f}, {:0.3f})".format(self.outline_id, self.ol[0][0], self.ol[0][1], self.ol[-1][-3], self.ol[-1][-2])) + six.print_(("ERR206: Error, outline {:s} should be closed but is not closed: first point ({:0.3f}, {:0.3f}), last point ({:0.3f}, {:0.3f})".format(self.outline_id, self.ol[0][0], self.ol[0][1], self.ol[-1][-3], self.ol[-1][-2]))) sys.exit(2) last_segment = list(self.ol[-1]) last_segment[-3] = self.ol[0][0] @@ -250,20 +251,20 @@ def check(self, figure_id=""): radian_epsilon = math.pi/1000 # if(len(self.ol)<2): - print("ERR179: Error, figure {:s}, outline {:s} with {:d} segments is too short. Add at leat two segment first.".format(figure_id, self.outline_id, len(self.ol))) + six.print_(("ERR179: Error, figure {:s}, outline {:s} with {:d} segments is too short. Add at leat two segment first.".format(figure_id, self.outline_id, len(self.ol)))) sys.exit(2) if(len(self.ol[0])!=3): - print("ERR222: Error, figure {:s}, outline {:s}, the StartPoint_length {:d} is not 3".format(figure_id, self.outline_id, len(self.ol[0]))) + six.print_(("ERR222: Error, figure {:s}, outline {:s}, the StartPoint_length {:d} is not 3".format(figure_id, self.outline_id, len(self.ol[0])))) sys.exit(2) for i in range(len(self.ol)): if((len(self.ol[i])!=3)and(len(self.ol[i])!=5)): - print("ERR226: Error, figure {:s}, outline {:s}, segment {:d}, length {:d} is not 3 or 5".format(figure_id, self.outline_id, i, len(self.ol[i]))) + six.print_(("ERR226: Error, figure {:s}, outline {:s}, segment {:d}, length {:d} is not 3 or 5".format(figure_id, self.outline_id, i, len(self.ol[i])))) sys.exit(2) if((self.ol[0][0]!=self.ol[-1][-3])or(self.ol[0][1]!=self.ol[-1][-2])): - print("ERR182: Error, figure {:s}, outline {:s} is not closed: first point ({:0.3f}, {:0.3f}), last point ({:0.3f}, {:0.3f})".format(figure_id, self.outline_id, self.ol[0][0], self.ol[0][1], self.ol[-1][-3], self.ol[-1][-2])) + six.print_(("ERR182: Error, figure {:s}, outline {:s} is not closed: first point ({:0.3f}, {:0.3f}), last point ({:0.3f}, {:0.3f})".format(figure_id, self.outline_id, self.ol[0][0], self.ol[0][1], self.ol[-1][-3], self.ol[-1][-2]))) sys.exit(2) if(self.ol[-1][-1]!=0): - print("ERR185: Error, figure {:s}, outline {:s}, last point router_bit_radius {:0.3f} is not 0.0".format(figure_id, self.outline_id, self.ol[-1][-1])) + six.print_(("ERR185: Error, figure {:s}, outline {:s}, last point router_bit_radius {:0.3f} is not 0.0".format(figure_id, self.outline_id, self.ol[-1][-1]))) sys.exit(2) # compute statistics on the outline stat = {} @@ -340,13 +341,13 @@ def check(self, figure_id=""): stat['y_min'] = min(stat['y_min'], self.ol[i+1][1], self.ol[i+1][3]) stat['y_max'] = max(stat['y_max'], self.ol[i+1][1], self.ol[i+1][3]) else: - print("ERR244: Error, figure_id {:s}, outline {:s}, segment {:d} unexpected length {:d}".format(figure_id, self.outline_id, i+1, len(self.ol[i+1]))) + six.print_(("ERR244: Error, figure_id {:s}, outline {:s}, segment {:d} unexpected length {:d}".format(figure_id, self.outline_id, i+1, len(self.ol[i+1])))) sys.exit(2) if(pt1_distanceol_stat['x_min'])or(self.stat['x_max']ol_stat['y_min'])or(self.stat['y_max']=len(self.outlines)): - print("ERR544: Error, figure {:s}, outline index {:d} is out of the range {:s}".format(self.figure_id, ai_index, len(self.outlines))) + six.print_(("ERR544: Error, figure {:s}, outline index {:d} is out of the range {:s}".format(self.figure_id, ai_index, len(self.outlines)))) sys.exit(2) r_outline = self.outlines[ai_index] return(r_outline) @@ -773,7 +774,7 @@ def get_outline_id(self, ai_outline_id): if(self.outlines[i].outline_id==ai_outline_id): idx = i if(idx==-1): - print("ERR558: Error, figure {:s}, outline_id {:s} does not exist".format(self.figure_id, ai_outline_id)) + six.print_(("ERR558: Error, figure {:s}, outline_id {:s} does not exist".format(self.figure_id, ai_outline_id))) sys.exit(2) r_outline = self.get_outline_index(idx) return(r_outline) @@ -792,7 +793,7 @@ def convert_from_old_format(self, ai_figure): this function should be only used during the transistion to the new format (Figure object) """ if(len(ai_figure)<1): - print("ERR701: Error, figure {:s}, convert_from_old_format failed because import list {:d} is 0".format(self.figure_id, len(ai_figure))) + six.print_(("ERR701: Error, figure {:s}, convert_from_old_format failed because import list {:d} is 0".format(self.figure_id, len(ai_figure)))) sys.exit(2) for i in range(len(ai_figure)): old_ol = ai_figure[i] @@ -863,7 +864,7 @@ def add_figure(self, ai_figure): """ add a figure to the collection and update the statistics """ if(not isinstance(ai_figure, Figure)): - print("ERR525: Error, figure_collection {:s}, add unexpected object {:s}".format(self.collection_id, ai_figure.figure_id)) + six.print_(("ERR525: Error, figure_collection {:s}, add unexpected object {:s}".format(self.collection_id, ai_figure.figure_id))) sys.exit(2) self.figures.append(copy.deepcopy(ai_figure)) # if the reference change, the stored object doesn't change #self.figures.append(copy.copy(ai_figure)) # todo: check the difference between copy() and deepcopy() @@ -922,7 +923,7 @@ def get_figure_index(self, ai_index): """ return the Figure object with the corresponding index in the figure list """ if(abs(ai_index)>=len(self.figures)): - print("ERR583: Error, figure_collection {:s}, figure index {:d} is out of the range {:s}".format(self.collection_id, ai_index, len(self.figures))) + six.print_(("ERR583: Error, figure_collection {:s}, figure index {:d} is out of the range {:s}".format(self.collection_id, ai_index, len(self.figures)))) sys.exit(2) r_figure = self.figures[ai_index] return(r_figure) @@ -936,7 +937,7 @@ def get_figure_id(self, ai_figure_id): if(self.figures[i].figure_id==ai_figure_id): idx = i if(idx==-1): - print("ERR597: Error, figure_collection {:s}, figure_id {:s} does not exist".format(self.collection_id, ai_figure_id)) + six.print_(("ERR597: Error, figure_collection {:s}, figure_id {:s} does not exist".format(self.collection_id, ai_figure_id))) sys.exit(2) r_figure = self.get_figure_index(idx) return(r_figure) @@ -972,19 +973,19 @@ def convert_from_old_format(self, ai_figure_collection): ################################################################ # # import for test only -import outline_backends -import design_output +from . import outline_backends +from . import design_output def test_c_xy(): """ test the API function c_xy() """ print("\nTest c_xy()") (x,y) = c_xy(5.0, 1.0, 0.0, 0.0) - print("c_xy 5.0, 1.0, 0, 0 : x {:0.3f} , y {:0.3f}".format(x,y)) + six.print_(("c_xy 5.0, 1.0, 0, 0 : x {:0.3f} , y {:0.3f}".format(x,y))) (x,y) = c_xy(3.0, -1.0, 2.0, -1.0) - print("c_xy 3.0, -1.0, 2, -1.0 : x {:0.3f} , y {:0.3f}".format(x,y)) + six.print_(("c_xy 3.0, -1.0, 2, -1.0 : x {:0.3f} , y {:0.3f}".format(x,y))) (x,y) = c_xy(5.0, 1.0, C=(-2,-3)) - print("c_xy 5.0, 1.0, C=(-2,-3) : x {:0.3f} , y {:0.3f}".format(x,y)) + six.print_(("c_xy 5.0, 1.0, C=(-2,-3) : x {:0.3f} , y {:0.3f}".format(x,y))) def test_draw_2d_1(): """ first complete test of the draw_2d @@ -1018,16 +1019,16 @@ def test_draw_2d_1(): fig3.merge_figure(fig1) fig3.merge_figure(fig2) tfc.add_figure(fig3) - print(tfc.stat_info()) - print(tfc.get_figure_id('first_figure').stat_info("test_figure_collection")) - print(tfc.get_figure_id('first_figure').get_outline_id('inner_shape').stat_info("test_figure_collection.first_figure")) - print(tfc.get_figure_id('first_figure').get_outline_id('inner_circle').stat_info("test_figure_collection.first_figure")) + six.print_((tfc.stat_info())) + six.print_((tfc.get_figure_id('first_figure').stat_info("test_figure_collection"))) + six.print_((tfc.get_figure_id('first_figure').get_outline_id('inner_shape').stat_info("test_figure_collection.first_figure"))) + six.print_((tfc.get_figure_id('first_figure').get_outline_id('inner_circle').stat_info("test_figure_collection.first_figure"))) old_figure_collection = tfc.convert_to_old_format() #print("dbg904: old_figure_collection: ", old_figure_collection) tfc2 = Figure_Collection("test_figure_collection_reload") tfc2.convert_from_old_format(old_figure_collection) - print(tfc2.stat_info()) - print(tfc2.get_figure_id('first_figure').stat_info("test_figure_collection_reload")) + six.print_((tfc2.stat_info())) + six.print_((tfc2.get_figure_id('first_figure').stat_info("test_figure_collection_reload"))) b_figure = design_output.cnc_cut_figure(tfc.get_figure_id('first_figure').convert_to_old_format(), "first_figure") #outline_backends.figure_simple_display(b_figure, (), "test") outline_backends.figure_simple_display(fig1.cnc_cut(), fig1.ideal(), "test") diff --git a/cnc25d/epicyclic_gearing.py b/cnc25d/epicyclic_gearing.py index 7f9f35c..265c9bd 100644 --- a/cnc25d/epicyclic_gearing.py +++ b/cnc25d/epicyclic_gearing.py @@ -29,7 +29,8 @@ # header for Python / FreeCAD compatibility ################################################################ -import cnc25d_api +from . import cnc25d_api +import six cnc25d_api.importing_freecad() #print("FreeCAD.Version:", FreeCAD.Version()) @@ -52,10 +53,10 @@ #import svgwrite #from dxfwrite import DXFEngine # cnc25d -import gearring -import gearwheel -import gear_profile # to get the high-level parameter to find the angle position -import axle_lid +from . import gearring +from . import gearwheel +from . import gear_profile # to get the high-level parameter to find the angle position +from . import axle_lid ################################################################ # epicyclic_gearing constraint_constructor @@ -380,14 +381,14 @@ def sun_gearwheel_constraint(c): #tooth_check = (c['sun_gear_tooth_nb'] + c['annulus_gear_tooth_nb'])%c['planet_nb'] tooth_check = (2*(c['sun_gear_tooth_nb'] + c['planet_gear_tooth_nb'])) % c['planet_nb'] if(tooth_check!=0): - print("WARN418: Warning, tooth_check {:d} is different from 0.".format(tooth_check)) + six.print_(("WARN418: Warning, tooth_check {:d} is different from 0.".format(tooth_check))) #print("tooth_check = (sun_nb {:d} + annulus_nb {:d}) % planet_nb {:d}".format(c['sun_gear_tooth_nb'], c['annulus_gear_tooth_nb'], c['planet_nb'])) - print("tooth_check = (2*(sun_nb {:d} + planet_nb {:d})) % planet_nb {:d}".format(c['sun_gear_tooth_nb'], c['planet_gear_tooth_nb'], c['planet_nb'])) + six.print_(("tooth_check = (2*(sun_nb {:d} + planet_nb {:d})) % planet_nb {:d}".format(c['sun_gear_tooth_nb'], c['planet_gear_tooth_nb'], c['planet_nb']))) for i in range(c['planet_nb']): a0_ai_diff = math.fmod(sun_angle_position[i]-sun_angle_position[0]+5.5*g2_pi_module_angle, g2_pi_module_angle) - 0.5*g2_pi_module_angle if(abs(a0_ai_diff)>radian_epsilon): - print("ERR414: Error, the i {:d} sun_angle_position {:0.5f} differ from the 0 sun_angle_position {:0.5f} with g2_pi_module_angle {:0.8f}".format(i, sun_angle_position[i], sun_angle_position[0], g2_pi_module_angle)) - print("dbg417: a0_ai_diff {:0.8f}".format(a0_ai_diff)) + six.print_(("ERR414: Error, the i {:d} sun_angle_position {:0.5f} differ from the 0 sun_angle_position {:0.5f} with g2_pi_module_angle {:0.8f}".format(i, sun_angle_position[i], sun_angle_position[0], g2_pi_module_angle))) + six.print_(("dbg417: a0_ai_diff {:0.8f}".format(a0_ai_diff))) sys.exit(2) gw_c['gear_initial_angle'] = sun_angle_position[0] return(gw_c) @@ -419,7 +420,7 @@ def epicyclic_gearing_constraint_check(c): c['carrier_crenel_rbr'] = c['cnc_router_bit_radius'] ## gearring_dedendum_to_hollow_pourcentage if((c['gearring_dedendum_to_hollow_pourcentage']>=100.0)or(c['gearring_dedendum_to_hollow_pourcentage']<0)): - print("ERR277: Error, gearring_dedendum_to_hollow_pourcentage {:0.3f} must be set between 0.0% and 100.0%".format(c['gearring_dedendum_to_hollow_pourcentage'])) + six.print_(("ERR277: Error, gearring_dedendum_to_hollow_pourcentage {:0.3f} must be set between 0.0% and 100.0%".format(c['gearring_dedendum_to_hollow_pourcentage']))) sys.exit(2) ## tooth number c['annulus_gear_tooth_nb'] = c['sun_gear_tooth_nb'] + 2 * c['planet_gear_tooth_nb'] @@ -432,12 +433,12 @@ def epicyclic_gearing_constraint_check(c): if(c['planet_nb']==0): c['planet_nb'] = c['planet_number_max'] if(c['planet_nb']>c['planet_number_max']): - print("ERR270: Error, planet_nb {:d} is bigger than planet_number_max {:d}".format(c['planet_nb'], c['planet_number_max'])) + six.print_(("ERR270: Error, planet_nb {:d} is bigger than planet_number_max {:d}".format(c['planet_nb'], c['planet_number_max']))) sys.exit(2) c['epicyclic_gearing_ratio'] = float(c['sun_gear_tooth_nb'])/(c['sun_gear_tooth_nb']+c['annulus_gear_tooth_nb']) ## gear_addendum_dedendum_parity_slack if((c['gear_addendum_dedendum_parity_slack']<0)or(c['gear_addendum_dedendum_parity_slack']>30)): - print("ERR274: Error, gear_addendum_dedendum_parity_slack {:0.3f} is out of the range 0..30".format(c['gear_addendum_dedendum_parity_slack'])) + six.print_(("ERR274: Error, gear_addendum_dedendum_parity_slack {:0.3f} is out of the range 0..30".format(c['gear_addendum_dedendum_parity_slack']))) sys.exit(2) c['addendum_dedendum_parity'] = 50.0-c['gear_addendum_dedendum_parity_slack']/2.0 c['first_planet_position_angle'] = c['planet_carrier_angle'] @@ -502,23 +503,23 @@ def epicyclic_gearing_constraint_check(c): # print("ERR443: Error, carrier_central_hole_diameter {:0.3f} is bigger than carrier_central_diameter {:0.3f}".format(c['carrier_central_hole_diameter'], c['carrier_central_diameter'])) # sys.exit(2) if(c['carrier_leg_hole_radius']>c['carrier_leg_radius']): - print("ERR446: Error, carrier_leg_hole_radius {:0.3f} is bigger than carrier_leg_radius {:0.3f}".format(c['carrier_leg_hole_radius'], c['carrier_leg_radius'])) + six.print_(("ERR446: Error, carrier_leg_hole_radius {:0.3f} is bigger than carrier_leg_radius {:0.3f}".format(c['carrier_leg_hole_radius'], c['carrier_leg_radius']))) sys.exit(2) if(c['carrier_peripheral_internal_radius']>c['sun_planet_length']): - print("ERR448: Error, carrier_peripheral_internal_radius {:0.3f} is bigger than sun_planet_length {:0.3f}".format(c['carrier_peripheral_internal_radius'], c['sun_planet_length'])) + six.print_(("ERR448: Error, carrier_peripheral_internal_radius {:0.3f} is bigger than sun_planet_length {:0.3f}".format(c['carrier_peripheral_internal_radius'], c['sun_planet_length']))) sys.exit(2) if(c['carrier_peripheral_internal_radius']<(c['carrier_central_radius']+3*c['carrier_sr'])): #print("WARN455: Warning, carrier_peripheral_internal_radius {:0.3f} is too small compare to carrier_central_radius {:0.3f} and carrier_smoothing_radius {:0.3f}".format(c['carrier_peripheral_internal_radius'], c['carrier_central_radius'], c['carrier_sr'])) c['carrier_hollow_disable'] = True if(c['carrier_peripheral_external_radius']<(c['sun_planet_length']+c['carrier_leg_radius'])): - print("WARN461: Warning, carrier_peripheral_external_radius {:0.3f} is too small compare to sun_planet_length {:0.3f} and carrier_leg_radius {:0.3f}".format(c['carrier_peripheral_external_radius'], c['sun_planet_length'], c['carrier_leg_radius'])) + six.print_(("WARN461: Warning, carrier_peripheral_external_radius {:0.3f} is too small compare to sun_planet_length {:0.3f} and carrier_leg_radius {:0.3f}".format(c['carrier_peripheral_external_radius'], c['sun_planet_length'], c['carrier_leg_radius']))) sys.exit(2) c['carrier_crenel'] = True if(c['carrier_crenel_height']==0): c['carrier_crenel'] = False if(c['carrier_crenel']): if(c['carrier_crenel_width']<7.0*c['carrier_crenel_rbr']): - print("ERR468: Error, carrier_crenel_width {:0.3f} is too small compare to carrier_crenel_router_bit_radius {:0.3f}".format(c['carrier_crenel_width'], c['carrier_crenel_rbr'])) + six.print_(("ERR468: Error, carrier_crenel_width {:0.3f} is too small compare to carrier_crenel_router_bit_radius {:0.3f}".format(c['carrier_crenel_width'], c['carrier_crenel_rbr']))) sys.exit(2) if(c['carrier_crenel_height']<3*c['carrier_crenel_rbr']): c['carrier_crenel_type'] = 2 @@ -527,48 +528,48 @@ def epicyclic_gearing_constraint_check(c): #print("dbg509: carrier_crenel_router_bit_radius {:0.3f} carrier_crenel_type {:d}".format(c['carrier_crenel_rbr'], c['carrier_crenel_type'])) if(c['carrier_hole_radius']>0): if(c['carrier_hole_position_radius']<(c['sun_planet_length']+c['carrier_leg_hole_radius']+c['carrier_hole_radius']+radian_epsilon)): - print("ERR544: Error, carrier_hole_position_radius {:0.3f} is too small compare to sun_planet_length {:0.3f}, carrier_leg_hole_radius {:0.3f} and carrier_hole_radius {:0.3f}".format(c['carrier_hole_position_radius'], c['sun_planet_length'], c['carrier_leg_hole_radius'], c['carrier_hole_radius'])) + six.print_(("ERR544: Error, carrier_hole_position_radius {:0.3f} is too small compare to sun_planet_length {:0.3f}, carrier_leg_hole_radius {:0.3f} and carrier_hole_radius {:0.3f}".format(c['carrier_hole_position_radius'], c['sun_planet_length'], c['carrier_leg_hole_radius'], c['carrier_hole_radius']))) sys.exit(2) if(c['carrier_hole_position_radius']>(c['carrier_peripheral_external_radius']-c['carrier_crenel_height']-c['carrier_hole_radius']-radian_epsilon)): - print("ERR548: Error, carrier_hole_position_radius {:0.3f} is too big compare to carrier_peripheral_external_radius {:0.3f} carrier_crenel_height {:0.3f} and carrier_hole_radius {:0.3f}".format(c['carrier_hole_position_radius'], c['carrier_peripheral_external_radius'], c['carrier_crenel_height'], c['carrier_hole_radius'])) + six.print_(("ERR548: Error, carrier_hole_position_radius {:0.3f} is too big compare to carrier_peripheral_external_radius {:0.3f} carrier_crenel_height {:0.3f} and carrier_hole_radius {:0.3f}".format(c['carrier_hole_position_radius'], c['carrier_peripheral_external_radius'], c['carrier_crenel_height'], c['carrier_hole_radius']))) sys.exit(2) if(c['carrier_double_hole_length']<0): - print("ERR658: Error, carrier_double_hole_length {:0.3f} should be positive".format(c['carrier_double_hole_length'])) + six.print_(("ERR658: Error, carrier_double_hole_length {:0.3f} should be positive".format(c['carrier_double_hole_length']))) sys.exit(2) elif(c['carrier_double_hole_length']>0): if(c['carrier_hole_radius']==0): - print("ERR662: Error, carrier_double_hole_length {:0.3f} is positive whereas carrier_hole_radius is set to zero".format(c['carrier_double_hole_length'])) + six.print_(("ERR662: Error, carrier_double_hole_length {:0.3f} is positive whereas carrier_hole_radius is set to zero".format(c['carrier_double_hole_length']))) sys.exit(2) ### top (axle-lid) c['top_clearance_radius'] = c['top_clearance_diameter']/2.0 if(c['top_clearance_radius'] == 0): c['top_clearance_radius'] = (c['carrier_peripheral_external_radius'] + c['holder_radius'])/2.0 # default value if(c['top_clearance_radius'] < c['carrier_peripheral_external_radius']): - print("ERR968: Error, top_clearance_radius {:0.3f} is smaller than carrier_peripheral_external_radius {:0.3f}".format(c['top_clearance_radius'], c['carrier_peripheral_external_radius'])) + six.print_(("ERR968: Error, top_clearance_radius {:0.3f} is smaller than carrier_peripheral_external_radius {:0.3f}".format(c['top_clearance_radius'], c['carrier_peripheral_external_radius']))) sys.exit(2) if(c['top_clearance_radius'] > c['holder_radius']): - print("ERR971: Error, top_clearance_radius {:0.3f} is bigger than holder_radius {:0.3f}".format(c['top_clearance_radius'], c['holder_radius'])) + six.print_(("ERR971: Error, top_clearance_radius {:0.3f} is bigger than holder_radius {:0.3f}".format(c['top_clearance_radius'], c['holder_radius']))) sys.exit(2) c['top_axle_hole_radius'] = c['top_axle_hole_diameter']/2.0 if(c['top_axle_hole_radius'] == 0): if(c['sun_axle_type'] != 'circle'): - print("WARN978: Warning, sun_axle_type {:s} is not set to circle but sun_axle_x_width {:0.3f} is used to set the top_axle_hole_diameter".format(c['sun_axle_type'], c['sun_axle_x_width'])) + six.print_(("WARN978: Warning, sun_axle_type {:s} is not set to circle but sun_axle_x_width {:0.3f} is used to set the top_axle_hole_diameter".format(c['sun_axle_type'], c['sun_axle_x_width']))) c['top_axle_hole_radius'] = c['sun_axle_x_width']/2.0 c['top_central_radius'] = c['top_central_diameter']/2.0 if(c['top_central_radius'] == 0): c['top_central_radius'] = 3*c['top_axle_hole_radius'] if(c['top_central_radius']c['holder_radius']): - print("ERR987: Error, top_central_radius {:0.3f} is bigger than holder_radius {:0.3f}".format(c['top_central_radius'], c['holder_radius'])) + six.print_(("ERR987: Error, top_central_radius {:0.3f} is bigger than holder_radius {:0.3f}".format(c['top_central_radius'], c['holder_radius']))) sys.exit(2) ### inout_in_hole_diameter #c['input_axle_shaft_radius'] = (c['input_gearwheel_tooth_nb']+2)*c['input_gearwheel_module']/2.0 # no, to avoid Z-axis issue, we don't want to make this radius as small as possible, but set it to carrier_peripheral_external_radius. Nice to have: input_axle_shaft_radius < (c['annulus_gear_tooth_nb']-2)*gear_module #c['input_axle_shaft_radius'] = c['carrier_peripheral_external_radius'] c['input_axle_shaft_radius'] = max((c['input_gearwheel_tooth_nb']+2)*c['input_gearwheel_module']/2.0, c['carrier_peripheral_external_radius']) if(c['input_axle_shaft_radius']>(c['annulus_gear_tooth_nb']-2)*c['gear_module']/2.0-radian_epsilon): - print("WARN910: Warning, input_axle_shaft_radius {:0.3f} is too big compare to annulus_gear_tooth_nb {:d} and gear_module {:0.3f}".format(c['input_axle_shaft_radius'], c['annulus_gear_tooth_nb'], c['gear_module'])) + six.print_(("WARN910: Warning, input_axle_shaft_radius {:0.3f} is too big compare to annulus_gear_tooth_nb {:d} and gear_module {:0.3f}".format(c['input_axle_shaft_radius'], c['annulus_gear_tooth_nb'], c['gear_module']))) c['inout_in_hole_diameter'] = 2*(c['input_axle_shaft_radius']+c['input_cover_extra_space']) ### inout_out_hole_diameter #output_axle_shaft_radius = (c['output_gearwheel_tooth_nb']+2)*c['output_gearwheel_module']/2.0 # no, it's not defined by the output gearwheel @@ -627,7 +628,7 @@ def carrier_crenel_outline(nai_radius): carrier_peripheral_portion_angle = 2*math.pi/(2*c['planet_nb']) carrier_peripheral_arc_half_angle = (carrier_peripheral_portion_angle - 2 * crenel_width_half_angle)/2.0 if(carrier_peripheral_arc_half_angle1)): - print("ERR730: Error, cos_imea {:0.3f} is out of the range -1,1".format(cos_imea)) + six.print_(("ERR730: Error, cos_imea {:0.3f} is out of the range -1,1".format(cos_imea))) sys.exit(2) imea = math.acos(cos_imea) # intersection carrier_leg_middle_radius and carrier_peripheral_internal_radius from planet @@ -767,7 +768,7 @@ def carrier_crenel_outline(nai_radius): imia = imia_0 + math.acos((planet_planet_length**2+0*c['carrier_leg_middle_radius']**2)/(2*planet_planet_length*c['carrier_leg_middle_radius'])) pla = (imea-imia)/2.0 if(pla0): if(g1_m_set): - print("ERR115: Error, too much constraints! the gear_module is already set to {:0.2f}!".format(g1_m)) + six.print_(("ERR115: Error, too much constraints! the gear_module is already set to {:0.2f}!".format(g1_m))) sys.exit(2) else: if((g1_type=='i')or(g1_type=='e')): @@ -327,7 +328,7 @@ def gear_profile_constraint_check(c): print("ERR116: Error, set second_gear_tooth_nb to use second_gear_primitive_diameter") sys.exit(2) elif(g1_m_set): - print("ERR117: Error, too much constraints! the gear_module is already set to {:0.2f}!".format(g1_m)) + six.print_(("ERR117: Error, too much constraints! the gear_module is already set to {:0.2f}!".format(g1_m))) sys.exit(2) else: if((g2_type=='i')or(g2_type=='e')): @@ -360,7 +361,7 @@ def gear_profile_constraint_check(c): # addendum_dedendum_parity g1_adp = float(c['gear_addendum_dedendum_parity'])/100 if((g1_adp<=0)or(g1_adp>=1)): - print("ERR118: Error, the gear_addendum_dedendum_parity {:0.2f} must be set strictly between 0% and 100%!".format(c['gear_addendum_dedendum_parity'])) + six.print_(("ERR118: Error, the gear_addendum_dedendum_parity {:0.2f} must be set strictly between 0% and 100%!".format(c['gear_addendum_dedendum_parity']))) sys.exit(2) g2_adp = 1-g1_adp if(c['second_gear_addendum_dedendum_parity']>0): @@ -371,7 +372,7 @@ def gear_profile_constraint_check(c): #print("WARN211: Warning, second_gear_addendum_dedendum_parity is used for irregular cases.") g2_adp = float(c['second_gear_addendum_dedendum_parity'])/100 if((g2_adp<=0)or(g2_adp>=1)): - print("ERR119: Error, the second_gear_addendum_dedendum_parity {:0.2f} must be set strictly between 0% and 100%!".format(c['second_gear_addendum_dedendum_parity'])) + six.print_(("ERR119: Error, the second_gear_addendum_dedendum_parity {:0.2f} must be set strictly between 0% and 100%!".format(c['second_gear_addendum_dedendum_parity']))) sys.exit(2) g1_param['addendum_dedendum_parity'] = g1_adp g2_param['addendum_dedendum_parity'] = g2_adp @@ -420,11 +421,11 @@ def gear_profile_constraint_check(c): g2_small_r = min(g2_ar, g2_dr) # small radius g2_big_r = max(g2_ar, g2_dr) # big radius if(g1_a_delta>aal+g2_d_delta): - print("WARN213: Warning, the addendum {:0.2f} of the first gear is too big, other the dedendum {:0.2f} of the other gear is too small (second_gear_additional_axis_length={:0.2f})!".format(g1_a_delta, g2_d_delta, aal)) + six.print_(("WARN213: Warning, the addendum {:0.2f} of the first gear is too big, other the dedendum {:0.2f} of the other gear is too small (second_gear_additional_axis_length={:0.2f})!".format(g1_a_delta, g2_d_delta, aal))) if(g2_a_delta>aal+g1_d_delta): - print("WARN214: Warning, the addendum {:0.2f} of the second gear is too big, other the dedendum {:0.2f} of the other gear is too small (second_gear_additional_axis_length={:0.2f})!".format(g2_a_delta, g1_d_delta, aal)) + six.print_(("WARN214: Warning, the addendum {:0.2f} of the second gear is too big, other the dedendum {:0.2f} of the other gear is too small (second_gear_additional_axis_length={:0.2f})!".format(g2_a_delta, g1_d_delta, aal))) if(g1_a_delta+g2_a_delta0): if(g1_brp_set): - print("ERR123: Error, too much constraints! gear_base_diameter is already set to {:0.2f}".format(g1_brp*2)) + six.print_(("ERR123: Error, too much constraints! gear_base_diameter is already set to {:0.2f}".format(g1_brp*2))) sys.exit(2) else: g1_brp = g1_pr*math.cos(c['gear_force_angle']) @@ -499,10 +500,10 @@ def gear_profile_constraint_check(c): print("ERR121: Error, set second_gear_tooth_nb to use second_gear_base_diameter_n") sys.exit(2) elif(g2_type=='l'): - print("ERR922: Error, the second gear type {:s} is a gearbar".format(g2_type)) + six.print_(("ERR922: Error, the second gear type {:s} is a gearbar".format(g2_type))) sys.exit(2) elif(g1_brn_set): - print("ERR122: Error, too much constraints! gear_base_diameter_n is already set to {:0.2f}".format(g1_brn*2)) + six.print_(("ERR122: Error, too much constraints! gear_base_diameter_n is already set to {:0.2f}".format(g1_brn*2))) sys.exit(2) else: g1_brn = float(c['second_gear_base_diameter_n']*g1_n)/(2*g2_n) @@ -512,17 +513,17 @@ def gear_profile_constraint_check(c): print("ERR821: Error, set second_gear_tooth_nb to use gearbar_slope_n") sys.exit(2) elif((g2_type=='e')or(g2_type=='i')): - print("ERR822: Error, the second gear type {:s} is not a gearbar".format(g2_type)) + six.print_(("ERR822: Error, the second gear type {:s} is not a gearbar".format(g2_type))) sys.exit(2) elif(g1_brn_set): - print("ERR823: Error, too much constraints! gear_base_diameter is already set to {:0.2f}".format(g1_brn*2)) + six.print_(("ERR823: Error, too much constraints! gear_base_diameter is already set to {:0.2f}".format(g1_brn*2))) sys.exit(2) else: g1_brn = g1_pr*math.cos(c['gearbar_slope_n']) g1_brn_set = True if(c['gear_force_angle_n']>0): if(g1_brn_set): - print("ERR123: Error, too much constraints! gear_base_diameter is already set to {:0.2f}".format(g1_brn*2)) + six.print_(("ERR123: Error, too much constraints! gear_base_diameter is already set to {:0.2f}".format(g1_brn*2))) sys.exit(2) else: g1_brn = g1_pr*math.cos(c['gear_force_angle_n']) @@ -530,7 +531,7 @@ def gear_profile_constraint_check(c): elif(g1_type=='l'): g1_sp_set = False if((c['gear_base_diameter']>0)or(c['gear_base_diameter_n']>0)): - print("ERR331: Error, for gearbar use gearbar_slope and gearbar_slope_n instead of gear_base_diameter {:0.3f} and gear_base_diameter_n {:0.3f}".format(c['gear_base_diameter'], c['gear_base_diameter_n'])) + six.print_(("ERR331: Error, for gearbar use gearbar_slope and gearbar_slope_n instead of gear_base_diameter {:0.3f} and gear_base_diameter_n {:0.3f}".format(c['gear_base_diameter'], c['gear_base_diameter_n']))) sys.exit(2) if(c['gearbar_slope']>0): g1_sp = c['gearbar_slope'] @@ -544,7 +545,7 @@ def gear_profile_constraint_check(c): print("ERR521: Error, set second_gear_tooth_nb to use second_gear_base_diameter") sys.exit(2) elif(g1_sp_set): - print("ERR523: Error, too much constraints! gearbar_slope_angle is already set to {:0.2f}".format(g1_sp)) + six.print_(("ERR523: Error, too much constraints! gearbar_slope_angle is already set to {:0.2f}".format(g1_sp))) sys.exit(2) else: g1_sp = math.acos(float(c['second_gear_base_diameter'])/(2*g2_pr)) @@ -566,7 +567,7 @@ def gear_profile_constraint_check(c): print("ERR531: Error, set second_gear_tooth_nb to use second_gear_base_diameter_n") sys.exit(2) elif(g1_sn_set): - print("ERR532: Error, too much constraints! gearbar_slope_angle_n is already set to {:0.2f}".format(g1_sp)) + six.print_(("ERR532: Error, too much constraints! gearbar_slope_angle_n is already set to {:0.2f}".format(g1_sp))) sys.exit(2) else: g1_sn = math.acos(float(c['second_gear_base_diameter_n'])/(2*g2_pr)) @@ -589,27 +590,27 @@ def gear_profile_constraint_check(c): # base radius check if((g1_type=='e')or(g1_type=='i')): if(g1_brp>g1_small_r): - print("WARN216: Warning, g1_brp {:0.2f} is bigger than g1_small_r {:0.2f}".format(g1_brp, g1_small_r)) + six.print_(("WARN216: Warning, g1_brp {:0.2f} is bigger than g1_small_r {:0.2f}".format(g1_brp, g1_small_r))) if(g1_brn>g1_small_r): - print("WARN246: Warning, g1_brn {:0.2f} is bigger than g1_small_r {:0.2f}".format(g1_brn, g1_small_r)) + six.print_(("WARN246: Warning, g1_brn {:0.2f} is bigger than g1_small_r {:0.2f}".format(g1_brn, g1_small_r))) if(g1_brp!=g1_brn): - print("WARN218: Warning, g1_brp {:0.2f} and g1_brn {:0.2f} are different. The gear_tooth are asymmetrical!".format(g1_brp, g1_brn)) + six.print_(("WARN218: Warning, g1_brp {:0.2f} and g1_brn {:0.2f} are different. The gear_tooth are asymmetrical!".format(g1_brp, g1_brn))) if(g1_brp>g1_big_r): - print("ERR616: Error, g1_brp {:0.2f} is bigger than g1_big_r {:0.2f}".format(g1_brp, g1_big_r)) + six.print_(("ERR616: Error, g1_brp {:0.2f} is bigger than g1_big_r {:0.2f}".format(g1_brp, g1_big_r))) sys.exit(2) if(g1_brn>g1_big_r): - print("ERR646: Error, g1_brn {:0.2f} is bigger than g1_big_r {:0.2f}".format(g1_brn, g1_big_r)) + six.print_(("ERR646: Error, g1_brn {:0.2f} is bigger than g1_big_r {:0.2f}".format(g1_brn, g1_big_r))) sys.exit(2) if((g2_type=='e')or(g2_type=='i')): if(g2_exist and (g2_brp>g2_small_r)): - print("WARN217: Warning, g2_brp {:0.2f} is bigger than g2_small_r {:0.2f}".format(g2_brp, g2_small_r)) + six.print_(("WARN217: Warning, g2_brp {:0.2f} is bigger than g2_small_r {:0.2f}".format(g2_brp, g2_small_r))) if(g2_exist and (g2_brn>g2_small_r)): - print("WARN247: Warning, g2_brn {:0.2f} is bigger than g2_small_r {:0.2f}".format(g2_brn, g2_small_r)) + six.print_(("WARN247: Warning, g2_brn {:0.2f} is bigger than g2_small_r {:0.2f}".format(g2_brn, g2_small_r))) if(g2_exist and (g2_brp>g2_big_r)): - print("ERR617: Error, g2_brp {:0.2f} is bigger than g2_big_r {:0.2f}".format(g2_brp, g2_big_r)) + six.print_(("ERR617: Error, g2_brp {:0.2f} is bigger than g2_big_r {:0.2f}".format(g2_brp, g2_big_r))) sys.exit(2) if(g2_exist and (g2_brn>g2_big_r)): - print("ERR647: Error, g2_brn {:0.2f} is bigger than g2_big_r {:0.2f}".format(g2_brn, g2_big_r)) + six.print_(("ERR647: Error, g2_brn {:0.2f} is bigger than g2_big_r {:0.2f}".format(g2_brn, g2_big_r))) sys.exit(2) g1_param['positive_base_radius'] = g1_brp g1_param['negative_base_radius'] = g1_brn @@ -652,12 +653,12 @@ def gear_profile_constraint_check(c): # hollow g1_h_delta = g1_thh*float(c['gear_hollow_height_pourcentage'])/100 if(g1_h_delta<1.05*g1_rbr): - print("WARN218: Warning, g1_h_delta {:0.2f} is smaller than the router_bit_radius {:0.2f}. gear_hollow_height_pourcentage {:0.2f} should be set to {:0.2f}".format(g1_h_delta, g1_rbr, c['gear_hollow_height_pourcentage'], 100.0*g1_rbr/g1_thh)) + six.print_(("WARN218: Warning, g1_h_delta {:0.2f} is smaller than the router_bit_radius {:0.2f}. gear_hollow_height_pourcentage {:0.2f} should be set to {:0.2f}".format(g1_h_delta, g1_rbr, c['gear_hollow_height_pourcentage'], 100.0*g1_rbr/g1_thh))) g1_h_delta = 1.05*g1_rbr g2_h_delta = g2_thh*float(c['second_gear_hollow_height_pourcentage'])/100 if(g2_exist): if(g2_h_delta<1.05*g2_rbr): - print("WARN219: Warning, g2_h_delta {:0.2f} is smaller than the second_router_bit_radius {:0.2f}. second_gear_hollow_height_pourcentage {:0.2f} should be set to {:0.2f}".format(g2_h_delta, g2_rbr, c['second_gear_hollow_height_pourcentage'], 100.0*g2_rbr/g2_thh)) + six.print_(("WARN219: Warning, g2_h_delta {:0.2f} is smaller than the second_router_bit_radius {:0.2f}. second_gear_hollow_height_pourcentage {:0.2f} should be set to {:0.2f}".format(g2_h_delta, g2_rbr, c['second_gear_hollow_height_pourcentage'], 100.0*g2_rbr/g2_thh))) g2_h_delta = 1.05*g2_rbr g1_hr = g1_dr - g1_as*g1_h_delta g2_hr = g2_dr - g2_as*g2_h_delta @@ -703,7 +704,7 @@ def gear_profile_constraint_check(c): g1_ple = 0 if(c['portion_tooth_nb']>0): # cut a portion of the first gear if(((g1_type=='e')or(g1_type=='i'))and(c['portion_tooth_nb']>=g1_n)): - print("ERR553: Error, the portion {:d} of gearwheel is bigger than the maximal number of teeth {:d}!".format(c['portion_tooth_nb'], g1_n)) + six.print_(("ERR553: Error, the portion {:d} of gearwheel is bigger than the maximal number of teeth {:d}!".format(c['portion_tooth_nb'], g1_n))) sys.exit(2) g1_ptn = c['portion_tooth_nb'] g1_pfe = c['portion_first_end'] @@ -942,7 +943,7 @@ def gear_profile_simulation_A(c): g2_rotation_speed_curve_table = [] tangential_friction_curve_table = [] ### start Tkinter - tk_root = Tkinter.Tk() + tk_root = tkinter.Tk() my_canvas = cnc25d_api.Two_Canvas(tk_root) # callback functions for display_backend def sub_canvas_graphics(ai_rotation_direction, ai_angle_position): diff --git a/cnc25d/gear_profile_outline.py b/cnc25d/gear_profile_outline.py index 62333e2..bd33af4 100644 --- a/cnc25d/gear_profile_outline.py +++ b/cnc25d/gear_profile_outline.py @@ -29,7 +29,7 @@ # header for Python / FreeCAD compatibility ################################################################ -import cnc25d_api +from . import cnc25d_api #cnc25d_api.importing_freecad() #print("FreeCAD.Version:", FreeCAD.Version()) @@ -54,7 +54,8 @@ #import svgwrite #from dxfwrite import DXFEngine # cnc25d -import small_geometry # use some well-tested functions from the internal of the cnc25d_api +from . import small_geometry # use some well-tested functions from the internal of the cnc25d_api +import six ################################################################ # module variable @@ -91,8 +92,8 @@ def involute_to_circle(ai_center, ai_base_radius, ai_initial_angle, ai_orientati u = ai_parameter # check the parameter if(u<0): - print("ERR099: Error, the parameter of the involute_to_circle must be positive {:0.8f}".format(u)) - print("dbg887: ai_center {:0.2f} {:0.2f} ai_base_radius {:0.2f} ai_initial_angle {:0.2f} ai_orientation {:d} ai_parameter {:0.2f}".format(ai_center[0], ai_center[1], ai_base_radius, ai_initial_angle, ai_orientation, ai_parameter)) + six.print_(("ERR099: Error, the parameter of the involute_to_circle must be positive {:0.8f}".format(u))) + six.print_(("dbg887: ai_center {:0.2f} {:0.2f} ai_base_radius {:0.2f} ai_initial_angle {:0.2f} ai_orientation {:d} ai_parameter {:0.2f}".format(ai_center[0], ai_center[1], ai_base_radius, ai_initial_angle, ai_orientation, ai_parameter))) sys.exit(2) # involute_to_circle of center (0,0), radius 1 and initial_angle = 0 with the parameter u px0 = math.cos(u)+u*math.sin(u) @@ -133,7 +134,7 @@ def search_point_of_involute_to_circle(ai_center, ai_base_radius, ai_initial_ang R = ai_altitude # check the paramter if(Rg_pr-radian_epsilon): - print("ERR987: Error, g_brp {:0.2f} is bigger than g_pr {:0.2f}!".format(g_brp, g_pr)) + six.print_(("ERR987: Error, g_brp {:0.2f} is bigger than g_pr {:0.2f}!".format(g_brp, g_pr))) sys.exit(2) (ippu, ippa, ippx, ippy, ippti) = search_point_of_involute_to_circle((g_ox, g_oy), g_brp, 0, 1, g_pr, initial_step, radian_epsilon_2) #ai_param['low_positive_primitive_angle'] = ippa # intersection of negative involute and the primitive circle if(g_brn>g_pr-radian_epsilon): - print("ERR988: Error, g_brn {:0.2f} is bigger than g_pr {:0.2f}!".format(g_brp, g_pr)) + six.print_(("ERR988: Error, g_brn {:0.2f} is bigger than g_pr {:0.2f}!".format(g_brp, g_pr))) sys.exit(2) (inpu, inpa, inpx, inpy, inpti) = search_point_of_involute_to_circle((g_ox, g_oy), g_brn, 0, -1, g_pr, initial_step, radian_epsilon_2) #ai_param['low_negative_primitive_angle'] = inpa @@ -297,12 +298,12 @@ def calc_low_level_gear_parameters(ai_param): top_land = pi_module_angle*g_adp-(addendum_positive_involute+addendum_negative_involute) #print("dbg298: top_land", top_land) [bug] dxf-top_land is negative whereas this top_land is still positive [todo] fix it if(top_land*g_ar0)or(g_ks*i2_dtri<0)): - print("ERR234: Error, i1_dtri {:0.3f} >0 or i2_dtri {:0.3f} < 0".format(g_ks*i1_dtri, g_ks*i2_dtri)) + six.print_(("ERR234: Error, i1_dtri {:0.3f} >0 or i2_dtri {:0.3f} < 0".format(g_ks*i1_dtri, g_ks*i2_dtri))) sys.exit(2) cos_i1_dtri = math.cos(i1_dtri) cos_i2_dtri = math.cos(i2_dtri) if((cos_i1_dtriradian_epsilon): - print("ERR972: Error, AI {:0.3f} and AI2 {:0.3f} are not equal".format(AI, AI2)) - print("dbg647: a {:0.3f} b {:0.3f} AIB {:0.3f} ABh {:0.3f}".format(a, b, AIB, ABh)) + six.print_(("ERR972: Error, AI {:0.3f} and AI2 {:0.3f} are not equal".format(AI, AI2))) + six.print_(("dbg647: a {:0.3f} b {:0.3f} AIB {:0.3f} ABh {:0.3f}".format(a, b, AIB, ABh))) sys.exit(2) if(abs(BI2-BI)>radian_epsilon): - print("ERR973: Error, BI {:0.3f} and BI2 {:0.3f} are not equal".format(BI, BI2)) + six.print_(("ERR973: Error, BI {:0.3f} and BI2 {:0.3f} are not equal".format(BI, BI2))) sys.exit(2) # select the method for AI and BI AI = AI2 @@ -459,11 +460,11 @@ def calc_low_level_gear_parameters(ai_param): top_land = pi_module*g_adp-(positive_addendum+negative_addendum) bottom_land = pi_module*(1-g_adp)-(positive_dedendum+negative_dedendum) if(top_landradian_epsilon)or(abs(first_hollow_slope_A[1][1]-second_hollow_slope_A[0][1])>radian_epsilon)): - print("ERR582: the hollow optimization intersection is wrong: x1 {:0.3f} x2 {:0.3f} y1 {:0.3f} y2 {:0.3f}".format(first_hollow_slope_A[1][0], second_hollow_slope_A[0][0], first_hollow_slope_A[1][1], second_hollow_slope_A[0][1])) + six.print_(("ERR582: the hollow optimization intersection is wrong: x1 {:0.3f} x2 {:0.3f} y1 {:0.3f} y2 {:0.3f}".format(first_hollow_slope_A[1][0], second_hollow_slope_A[0][0], first_hollow_slope_A[1][1], second_hollow_slope_A[0][1]))) #hollow_A = [] #hollow_A.extend(first_hollow_slope_A) #hollow_A.extend(second_hollow_slope_A) @@ -849,7 +850,7 @@ def gearbar_profile_outline(ai_low_parameters, ai_tangential_position): l_negative_slope = slope_outline(g_ox, g_oy, g_bi, gb_n_offset, g_sn, -1, g_aln, g_dln, g_hln, g_stn, g_rbr, tangential_position+pi_module) # negative slope if(ho): if((abs(l_negative_slope[0][0]-l_positive_slope[1][0])>radian_epsilon)or(abs(l_negative_slope[0][1]-l_positive_slope[1][1])>radian_epsilon)): - print("ERR583: the gearbar hollow optimization intersection is wrong: x1 {:0.3f} x2 {:0.3f} y1 {:0.3f} y2 {:0.3f}".format(l_positive_slope[1][0], l_negative_slope[0][0], l_positive_slope[1][1], l_negative_slope[0][1])) + six.print_(("ERR583: the gearbar hollow optimization intersection is wrong: x1 {:0.3f} x2 {:0.3f} y1 {:0.3f} y2 {:0.3f}".format(l_positive_slope[1][0], l_negative_slope[0][0], l_positive_slope[1][1], l_negative_slope[0][1]))) sys.exit(2) gearbar_A.extend(l_positive_slope) if(ho): @@ -935,12 +936,12 @@ def calc_real_force_angle(ai_g1_type, ai_g1_pr, ai_g1_br, ai_g2_type, ai_g2_pr, r_real_force_angle = math.acos(float(ai_g1_br+ai_g2_br)/(ai_g1_pr+ai_g2_pr+ai_aal)) elif((ai_g1_type=='i')and(ai_g2_type=='e')): # i-e if(ai_g2_pr>ai_g1_pr): - print("ERR546: Error, the gearring radius {:0.3f} must be bigger gearwheel radius {:0.3f}".format(ai_g1_pr, ai_g2_pr)) + six.print_(("ERR546: Error, the gearring radius {:0.3f} must be bigger gearwheel radius {:0.3f}".format(ai_g1_pr, ai_g2_pr))) sys.exit(2) r_real_force_angle = math.acos(float(ai_g1_br-ai_g2_br)/(ai_g1_pr-(ai_g2_pr+ai_aal))) elif((ai_g1_type=='e')and(ai_g2_type=='i')): # e-i if(ai_g1_pr>ai_g2_pr): - print("ERR547: Error, the gearring radius {:0.3f} must be bigger gearwheel radius {:0.3f}".format(ai_g2_pr, ai_g1_pr)) + six.print_(("ERR547: Error, the gearring radius {:0.3f} must be bigger gearwheel radius {:0.3f}".format(ai_g2_pr, ai_g1_pr))) sys.exit(2) r_real_force_angle = math.acos(float(ai_g2_br-ai_g1_br)/(ai_g2_pr-(ai_g1_pr+ai_aal))) elif((ai_g1_type=='l')and(ai_g2_type=='e')): # l-e @@ -948,7 +949,7 @@ def calc_real_force_angle(ai_g1_type, ai_g1_pr, ai_g1_br, ai_g2_type, ai_g2_pr, elif((ai_g1_type=='e')and(ai_g2_type=='l')): # e-l r_real_force_angle = ai_g2_sa else: - print("ERR221: Error, the gear type combination {:s}-{:s} does not exist!".format(ai_g1_type, ai_g2_type)) + six.print_(("ERR221: Error, the gear type combination {:s}-{:s} does not exist!".format(ai_g1_type, ai_g2_type))) sys.exit(2) return(r_real_force_angle) @@ -1047,7 +1048,7 @@ def pre_g2_position_calculation(ai_g1_param, ai_g2_param, ai_aal, ai_g1g2_a, ai_ # alternative for AB AB2 = math.sqrt((g2_ox-g1_ox)**2+(g2_oy-g1_oy)**2) if(abs(AB2-AB)>radian_epsilon): - print("ERR414: Error with the calculation of AB {:0.3f} or {:0.3f}".format(AB, AB2)) + six.print_(("ERR414: Error with the calculation of AB {:0.3f} or {:0.3f}".format(AB, AB2))) sys.exit(2) # KL (see documentation graphic gear_position.svg), used only with e-e, e-i and i-e KL_rp = math.sin(rfa_rp)*AB @@ -1056,10 +1057,10 @@ def pre_g2_position_calculation(ai_g1_param, ai_g2_param, ai_aal, ai_g1g2_a, ai_ KL_rp2 = math.sqrt(AB**2 - (g1_ks*g1_br_rp+g2_ks*g2_br_rp)**2) # kind of pythagor KL_rn2 = math.sqrt(AB**2 - (g1_ks*g1_br_rn+g2_ks*g2_br_rn)**2) # kind of pythagor if(abs(KL_rp2-KL_rp)>radian_epsilon): - print("ERR815: Error, KL_rp {:0.3f} and KL_rp2 {:0.3f} are too different!".format(KL_rp, KL_rp2)) + six.print_(("ERR815: Error, KL_rp {:0.3f} and KL_rp2 {:0.3f} are too different!".format(KL_rp, KL_rp2))) sys.exit(2) if(abs(KL_rn2-KL_rn)>radian_epsilon): - print("ERR876: Error, KL_rn {:0.3f} and KL_rn2 {:0.3f} are too different!".format(KL_rn, KL_rn2)) + six.print_(("ERR876: Error, KL_rn {:0.3f} and KL_rn2 {:0.3f} are too different!".format(KL_rn, KL_rn2))) sys.exit(2) # KE, BE, BD KE1_rp = 0 # default value for g_type = 'e' or 'i' @@ -1219,7 +1220,7 @@ def g2_position_calculation(ai_place_low_param, ai_rotation_direction, ai_g1_pos ABC = 0 elif(min_ABC+med_ABCradian_epsilon_1000): - print("ERR689: Error in the calculation of BAC {:0.3f} or BAC2 {:0.3f} !".format(BAC, BAC2)) + six.print_(("ERR689: Error in the calculation of BAC {:0.3f} or BAC2 {:0.3f} !".format(BAC, BAC2))) sys.exit(2) # check ABC and ABC2 if(abs(ABC2-ABC)>radian_epsilon_1000): - print("ERR688: Error in the calculation of ABC {:0.3f} or ABC2 {:0.3f} !".format(ABC, ABC2)) + six.print_(("ERR688: Error in the calculation of ABC {:0.3f} or ABC2 {:0.3f} !".format(ABC, ABC2))) sys.exit(2) #print("dbg334: BAC: {:0.3f}".format(BAC)) #print("dbg335: ABC: {:0.3f}".format(ABC)) @@ -1255,7 +1256,7 @@ def g2_position_calculation(ai_place_low_param, ai_rotation_direction, ai_g1_pos if((g1_type=='e')or(g1_type=='i')): g1_sra2 = rd*g1_ks*math.atan(g1_contact_u) if(abs(g1_sra2-g1_sra)>radian_epsilon_100): - print("ERR417: Error in calculation of g1_sra {:0.3f} or g1_sra2 {:0.3f}".format(g1_sra, g1_sra2)) + six.print_(("ERR417: Error in calculation of g1_sra {:0.3f} or g1_sra2 {:0.3f}".format(g1_sra, g1_sra2))) sys.exit(2) ## speed of c1 (contact point of g1) # c1 speed @@ -1279,10 +1280,10 @@ def g2_position_calculation(ai_place_low_param, ai_rotation_direction, ai_g1_pos if((g1_type=='e')or(g1_type=='i')): g2_contact_u1 = g1_ks*float(KL - g2_ks*g1_contact_u*g1_br)/g2_br if(abs(g2_contact_u2-g2_contact_u1)>radian_epsilon_10): - print("ERR331: Error in the calculation of g2_contact_u1 {:0.3f} or g2_contact_u2 {:0.3f}".format(g2_contact_u1, g2_contact_u2)) + six.print_(("ERR331: Error in the calculation of g2_contact_u1 {:0.3f} or g2_contact_u2 {:0.3f}".format(g2_contact_u1, g2_contact_u2))) sys.exit(2) if(abs(g2_contact_u3-g2_contact_u1)>radian_epsilon_10): - print("ERR332: Error in the calculation of g2_contact_u1 {:0.3f} or g2_contact_u3 {:0.3f}".format(g2_contact_u1, g2_contact_u3)) + six.print_(("ERR332: Error in the calculation of g2_contact_u1 {:0.3f} or g2_contact_u3 {:0.3f}".format(g2_contact_u1, g2_contact_u3))) sys.exit(2) g2_contact_u = g2_contact_u3 # select the method for g2_contact_u ## c2_position @@ -1291,7 +1292,7 @@ def g2_position_calculation(ai_place_low_param, ai_rotation_direction, ai_g1_pos (c2x, c2y, t2i) = sample_of_gear_tooth_profile((g2_ox, g2_oy), g2_br, g2_position+g2_lo, -1*rd*g1_ks, 0, g2_contact_u) #print("dbg326: g2_position {:0.3f} g2_lo {:0.3f} g2_contact_u {:0.3f} t2i {:0.3f}".format(g2_position, g2_lo, g2_contact_u, t2i)) if(abs(math.fmod(ti-t2i+4.5*math.pi, math.pi) - 0.5*math.pi)>radian_epsilon_1000): - print("ERR874: Error, the tangents ti {:0.3f} and t2i {:0.3f} are not equal (modulo pi)".format(ti, t2i)) + six.print_(("ERR874: Error, the tangents ti {:0.3f} and t2i {:0.3f} are not equal (modulo pi)".format(ti, t2i))) sys.exit(2) #print("dbg632: g2_ox {:0.3f} g2_oy {:0.3f} g2_br {:0.3f}".format(g2_ox, g2_oy, g2_br)) ## speed of c2 (contact point of g2) @@ -1301,8 +1302,8 @@ def g2_position_calculation(ai_place_low_param, ai_rotation_direction, ai_g1_pos # alternative c2_speed_tangential2 = rd*g1_ks*c2_speed_radial*g2_contact_u if(abs(c2_speed_tangential2-c2_speed_tangential)>radian_epsilon_10): - print("ERR336: Error in the calculation of c2_speed_tangential {:0.3f} or c2_speed_tangential2 {:0.3f}".format(c2_speed_tangential, c2_speed_tangential2)) - print("dbg967: radian_epsilon_1000 {:0.6f} radian_epsilon_100000 {:0.6f}".format(radian_epsilon_1000, radian_epsilon_100000)) + six.print_(("ERR336: Error in the calculation of c2_speed_tangential {:0.3f} or c2_speed_tangential2 {:0.3f}".format(c2_speed_tangential, c2_speed_tangential2))) + six.print_(("dbg967: radian_epsilon_1000 {:0.6f} radian_epsilon_100000 {:0.6f}".format(radian_epsilon_1000, radian_epsilon_100000))) sys.exit(2) g2_rotation_speed = float(c2_speed)/BC elif(g2_type=='l'): # linear-gear (aka gearbar) @@ -1314,7 +1315,7 @@ def g2_position_calculation(ai_place_low_param, ai_rotation_direction, ai_g1_pos c2y = g2_oy + rd*BE2*math.sin(g2_bi-math.pi/2) + dc*math.sin(g2_bi-math.pi/2-rd*g2_sa) #print("dbg989: g2_position {:0.3f} dc {:0.3f}".format(g2_position, dc)) if(abs(math.fmod(ti - (g2_bi-1*rd*g2_sa)+4.5*math.pi, math.pi)-0.5*math.pi)>radian_epsilon_1000): - print("ERR875: Error, the tangents ti {:0.3f} and slope g2_sa {:0.3f} are not equal (modulo pi)".format(ti, g2_sa)) + six.print_(("ERR875: Error, the tangents ti {:0.3f} and slope g2_sa {:0.3f} are not equal (modulo pi)".format(ti, g2_sa))) sys.exit(2) c2_speed_radial = c1_speed_radial c2_speed = float(c2_speed_radial)/math.cos(g2_sa) @@ -1366,7 +1367,7 @@ def info_on_real_force_angle(ai_g1_param, ai_g2_param, ai_sys_param, ai_rotation elif(ai_rotation_direction==-1): rotation_name = 'Negative' else: - print("ERR663: Error, ai_rotation_direction {:d} can only be 1 or -1!".format(ai_rotation_direction)) + six.print_(("ERR663: Error, ai_rotation_direction {:d} can only be 1 or -1!".format(ai_rotation_direction))) sys.exit(2) # get the interesting high-level parameters rd = ai_rotation_direction diff --git a/cnc25d/gearbar.py b/cnc25d/gearbar.py index f21ba29..57e5f20 100644 --- a/cnc25d/gearbar.py +++ b/cnc25d/gearbar.py @@ -30,7 +30,8 @@ # header for Python / FreeCAD compatibility ################################################################ -import cnc25d_api +from . import cnc25d_api +import six cnc25d_api.importing_freecad() #print("FreeCAD.Version:", FreeCAD.Version()) @@ -53,7 +54,7 @@ #import svgwrite #from dxfwrite import DXFEngine # cnc25d -import gear_profile +from . import gear_profile ################################################################ # inheritance from gear_profile @@ -126,7 +127,7 @@ def gearbar_constraint_check(c): c['gearbar_hole_radius'] = float(c['gearbar_hole_diameter'])/2 # c['gearbar_hole_height_position'] if((c['gearbar_hole_height_position']+c['gearbar_hole_radius'])>c['gearbar_height']): - print("ERR215: Error, gearbar_hole_height_position {:0.3} and gearbar_hole_radius {:0.3f} are too big compare to gearbar_height {:0.3f} !".format(c['gearbar_hole_height_position'], c['gearbar_hole_radius'], c['gearbar_height'])) + six.print_(("ERR215: Error, gearbar_hole_height_position {:0.3} and gearbar_hole_radius {:0.3f} are too big compare to gearbar_height {:0.3f} !".format(c['gearbar_hole_height_position'], c['gearbar_hole_radius'], c['gearbar_height']))) sys.exit(2) # c['gearbar_hole_increment'] if(c['gearbar_hole_increment']==0): @@ -156,7 +157,7 @@ def gearbar_constraint_check(c): bottom_land = gear_profile_parameters['g1_param']['bottom_land'] top_land = gear_profile_parameters['g1_param']['top_land'] if((top_land + full_positive_slope + bottom_land + full_negative_slope)!=c['pi_module']): - print("ERR269: Error with top_land {:0.3f} full_positive_slope {:0.3f} bottom_land {:0.3f} full_negative_slope {:0.3f} and pi_module {:0.3f}".format(top_land, full_positive_slope, bottom_land, full_negative_slope, c['pi_module'])) + six.print_(("ERR269: Error with top_land {:0.3f} full_positive_slope {:0.3f} bottom_land {:0.3f} full_negative_slope {:0.3f} and pi_module {:0.3f}".format(top_land, full_positive_slope, bottom_land, full_negative_slope, c['pi_module']))) sys.exit(2) if(pfe==0): c['first_tooth_position'] = full_positive_slope + bottom_land + full_negative_slope + float(top_land)/2 @@ -168,7 +169,7 @@ def gearbar_constraint_check(c): c['first_tooth_position'] = float(bottom_land)/2 + full_negative_slope + float(top_land)/2 else: # no gear_profile, just a circle if(c['gear_primitive_diameter']c['minimal_gear_profile_height']): - print("ERR269: Error, gearbar_hole_height_position {:0.3f} and gearbar_hole_radius {:0.3f} are too big compare to minimal_gear_profile_height {:0.3f}".format(c['gearbar_hole_height_position'], c['gearbar_hole_radius'], c['minimal_gear_profile_height'])) + six.print_(("ERR269: Error, gearbar_hole_height_position {:0.3f} and gearbar_hole_radius {:0.3f} are too big compare to minimal_gear_profile_height {:0.3f}".format(c['gearbar_hole_height_position'], c['gearbar_hole_radius'], c['minimal_gear_profile_height']))) sys.exit(2) # pi_module if(c['gearbar_hole_radius']>0): diff --git a/cnc25d/gearring.py b/cnc25d/gearring.py index 07c4bf6..bd952d0 100644 --- a/cnc25d/gearring.py +++ b/cnc25d/gearring.py @@ -30,7 +30,7 @@ # header for Python / FreeCAD compatibility ################################################################ -import cnc25d_api +from . import cnc25d_api #cnc25d_api.importing_freecad() #print("FreeCAD.Version:", FreeCAD.Version()) @@ -53,8 +53,9 @@ #import svgwrite #from dxfwrite import DXFEngine # cnc25d -import gear_profile -import gearwheel # gearwheel.marked_circle_crenel() +from . import gear_profile +from . import gearwheel # gearwheel.marked_circle_crenel() +import six ################################################################ @@ -176,7 +177,7 @@ def gearring_constraint_check(c): gear_module = gear_profile_parameters['g1_param']['module'] else: # no gear_profile, just a circle if(c['gear_primitive_diameter']0): if((0.9*holder_side_straigth_length)(c['holder_hole_position_radius']-c['holder_hole_radius'])): - print("ERR303: Error, holder-hole are too closed from the gear_hollow_circle: maximal_gear_profile_radius {:0.3f} holder_hole_position_radius {:0.3f} holder_hole_radius {:0.3f}".format(c['maximal_gear_profile_radius'], c['holder_hole_position_radius'], c['holder_hole_radius'])) + six.print_(("ERR303: Error, holder-hole are too closed from the gear_hollow_circle: maximal_gear_profile_radius {:0.3f} holder_hole_position_radius {:0.3f} holder_hole_radius {:0.3f}".format(c['maximal_gear_profile_radius'], c['holder_hole_position_radius'], c['holder_hole_radius']))) sys.exit(2) # holder_hole_mark_nb if((c['holder_hole_mark_nb']<0)or(c['holder_hole_mark_nb']>c['holder_crenel_number'])): - print("ERR294: Error, holder_hole_mark_nb {:d} is out of its range 0..{:d}".format(c['holder_hole_mark_nb'], c['holder_crenel_number'])) + six.print_(("ERR294: Error, holder_hole_mark_nb {:d} is out of its range 0..{:d}".format(c['holder_hole_mark_nb'], c['holder_crenel_number']))) sys.exit(2) # holder_double_hole c['holder_double_hole_radius'] = c['holder_double_hole_diameter']/2.0 c['holder_double_hole_position_radius'] = c['holder_hole_position_radius'] + c['holder_double_hole_position'] if(c['holder_double_hole_length']<0): - print("ERR304: Error, holder_double_hole_length {:0.3f} should be positive".format(c['holder_double_hole_length'])) + six.print_(("ERR304: Error, holder_double_hole_length {:0.3f} should be positive".format(c['holder_double_hole_length']))) sys.exit(2) elif(c['holder_double_hole_length']>0): if(c['holder_double_hole_radius']==0): - print("ERR308: Error, holder_double_hole_length {:0.3f} is positive whereas holder_double_hole_radius is set to zero".format(c['holder_double_hole_length'])) + six.print_(("ERR308: Error, holder_double_hole_length {:0.3f} is positive whereas holder_double_hole_radius is set to zero".format(c['holder_double_hole_length']))) sys.exit(2) if(c['holder_double_hole_position']!=0): if(c['holder_double_hole_radius']==0): - print("ERR319: Error, holder_double_hole_position {:0.3f} is set whereas holder_double_hole_radius is still set to zero".format(c['holder_double_hole_position'])) + six.print_(("ERR319: Error, holder_double_hole_position {:0.3f} is set whereas holder_double_hole_radius is still set to zero".format(c['holder_double_hole_position']))) sys.exit(2) if(c['holder_double_hole_radius']<0): - print("ERR322: Error, holder_double_hole_radius {:0.3f} must be positive or null".format(c['holder_double_hole_radius'])) + six.print_(("ERR322: Error, holder_double_hole_radius {:0.3f} must be positive or null".format(c['holder_double_hole_radius']))) sys.exit(2) elif(c['holder_double_hole_radius']>0): if(c['holder_double_hole_length']==0): - print("ERR326: Error, holder_double_hole_length must be positive when holder_double_hole_radius {:0.3f} is positive".format(c['holder_double_hole_radius'])) + six.print_(("ERR326: Error, holder_double_hole_length must be positive when holder_double_hole_radius {:0.3f} is positive".format(c['holder_double_hole_radius']))) sys.exit(2) # holder_double_hole_mark_nb if((c['holder_double_hole_mark_nb']<0)or(c['holder_double_hole_mark_nb']>c['holder_crenel_number'])): - print("ERR333: Error, holder_double_hole_mark_nb {:d} is out of its range 0..{:d}".format(c['holder_double_hole_mark_nb'], c['holder_crenel_number'])) + six.print_(("ERR333: Error, holder_double_hole_mark_nb {:d} is out of its range 0..{:d}".format(c['holder_double_hole_mark_nb'], c['holder_crenel_number']))) sys.exit(2) ## holder_hole_B holder_hole_B_radius = float(c['holder_hole_B_diameter'])/2 @@ -266,7 +267,7 @@ def gearring_constraint_check(c): c['holder_hole_B_crenel_list_bis'] = [ 0 for i in range(c['holder_crenel_number']) ] for i in range(len(c['holder_hole_B_crenel_list'])): if((int(c['holder_hole_B_crenel_list'][i])<0)or(int(c['holder_hole_B_crenel_list'][i])>=c['holder_crenel_number'])): - print("ERR286: Error, the holder_hole_B_crenel_list index {:s} is out of the range 0..{:d}".format(c['holder_hole_B_crenel_list'][i], c['holder_crenel_number'])) + six.print_(("ERR286: Error, the holder_hole_B_crenel_list index {:s} is out of the range 0..{:d}".format(c['holder_hole_B_crenel_list'][i], c['holder_crenel_number']))) sys.exit(2) c['holder_hole_B_crenel_list_bis'][int(c['holder_hole_B_crenel_list'][i])] = 1 #print("dbg358: holder_hole_B_crenel_list_bis:", c['holder_hole_B_crenel_list_bis']) @@ -293,7 +294,7 @@ def gearring_constraint_check(c): #print("dbg378: holder_smoothing_radius_list:", c['holder_smoothing_radius_list']) # if(c['holder_crenel_number_cut']>c['holder_crenel_number']): - print("ERR288: Error, holder_crenel_number_cut {:d} must be smaller than holder_crenel_number {:d}".format(c['holder_crenel_number_cut'], c['holder_crenel_number'])) + six.print_(("ERR288: Error, holder_crenel_number_cut {:d} must be smaller than holder_crenel_number {:d}".format(c['holder_crenel_number_cut'], c['holder_crenel_number']))) sys.exit(2) ### return(c) @@ -351,7 +352,7 @@ def gearring_2d_construction(c): elif(c['holder_crenel_number']>0): angle_incr = 2*math.pi/c['holder_crenel_number'] if((angle_incr-2*c['holder_crenel_half_angle'])0): if(c['crenel_number']>0): - print("ERR255: Error, crenel_tooth_align {:d} and crenel_number {:d} are set together".format(c['crenel_tooth_align'], c['crenel_number'])) + six.print_(("ERR255: Error, crenel_tooth_align {:d} and crenel_number {:d} are set together".format(c['crenel_tooth_align'], c['crenel_number']))) sys.exit(2) if(c['crenel_angle']!=0): - print("ERR258: Error, crenel_tooth_align {:d} and crenel_angle {:0.3f} are set together".format(c['crenel_tooth_align'], c['crenel_angle'])) + six.print_(("ERR258: Error, crenel_tooth_align {:d} and crenel_angle {:0.3f} are set together".format(c['crenel_tooth_align'], c['crenel_angle']))) sys.exit(2) if(c['gear_tooth_nb']==0): - print("ERR261: Error, crenel_tooth_align {:d} set and gear_tooth_nb {:d} is set to zero".format(c['crenel_tooth_align'], c['gear_tooth_nb'])) + six.print_(("ERR261: Error, crenel_tooth_align {:d} set and gear_tooth_nb {:d} is set to zero".format(c['crenel_tooth_align'], c['gear_tooth_nb']))) sys.exit(2) c['crenel_number'] = int(c['gear_tooth_nb']/c['crenel_tooth_align']) c['crenel_angle'] = c['gear_initial_angle'] @@ -196,14 +197,14 @@ def gearwheel_constraint_check(c): #print("dbg266: crenel_number {:d} crenel_angle {:0.3f} crenel_increment_angle {:0.3f}".format(c['crenel_number'], c['crenel_angle'], crenel_increment_angle)) # crenel_mark_nb if((c['crenel_mark_nb']<0)or(c['crenel_mark_nb']>c['crenel_number'])): - print("ERR233: Error, crenel_mark_nb {:d} is out of the range 0..{:d}".format(c['crenel_mark_nb'], c['crenel_number'])) + six.print_(("ERR233: Error, crenel_mark_nb {:d} is out of the range 0..{:d}".format(c['crenel_mark_nb'], c['crenel_number']))) sys.exit(2) # crenel_diameter crenel_diameter = c['crenel_diameter'] if(crenel_diameter==0): crenel_diameter = axle_diameter if(crenel_diameterminimal_gear_profile_radius-radian_epsilon): # non sense case - print("ERR218: Error, axle_radius {:0.3f} is bigger than minimal_gear_profile_radius {:0.3f}".format(c['axle_radius'], minimal_gear_profile_radius)) + six.print_(("ERR218: Error, axle_radius {:0.3f} is bigger than minimal_gear_profile_radius {:0.3f}".format(c['axle_radius'], minimal_gear_profile_radius))) sys.exit(2) c['wheel_hollow_external_radius'] = c['wheel_hollow_external_diameter']/2.0 c['wheel_hollow_internal_radius'] = c['wheel_hollow_internal_diameter']/2.0 @@ -240,63 +241,63 @@ def gearwheel_constraint_check(c): if(c['wheel_hollow_external_radius']==0): # set the default value c['wheel_hollow_external_radius'] = minimal_gear_profile_radius - 2.5*g1_m if(c['wheel_hollow_external_radius']c['wheel_hollow_external_radius']-2.1*c['wheel_hollow_rbr']): # remove the default value - print("WARN228: Warning, the wheel_hollow_internal_radius default value {:0.3f} can not be set!".format(c['wheel_hollow_internal_radius'])) + six.print_(("WARN228: Warning, the wheel_hollow_internal_radius default value {:0.3f} can not be set!".format(c['wheel_hollow_internal_radius']))) c['wheel_hollow_internal_radius'] = 0 c['wheel_hollow_leg_number'] = 0 if(c['wheel_hollow_router_bit_radius']==0): # set the default value c['wheel_hollow_rbr'] = (c['wheel_hollow_external_radius']-c['wheel_hollow_internal_radius'])/5.0 if(c['wheel_hollow_rbr']0): # wheel_hollow_external_diameter if(c['wheel_hollow_external_radius'] > minimal_gear_profile_radius-radian_epsilon): - print("ERR733: Error, wheel_hollow_external_radius {:0.2f} is bigger than the gear_hollow_radius {:0.2f}!".format(c['wheel_hollow_external_radius'], minimal_gear_profile_radius)) + six.print_(("ERR733: Error, wheel_hollow_external_radius {:0.2f} is bigger than the gear_hollow_radius {:0.2f}!".format(c['wheel_hollow_external_radius'], minimal_gear_profile_radius))) sys.exit(2) if(c['wheel_hollow_external_radius'] < c['wheel_hollow_internal_radius']+2*c['wheel_hollow_rbr']+radian_epsilon): - print("ERR734: Error, wheel_hollow_external_radius {:0.2f} is too small compare to wheel_hollow_internal_radius {:0.2f} and wheel_hollow_router_bit_radius {:0.2f}!".format(c['wheel_hollow_external_radius'], c['wheel_hollow_internal_radius'], c['wheel_hollow_rbr'])) + six.print_(("ERR734: Error, wheel_hollow_external_radius {:0.2f} is too small compare to wheel_hollow_internal_radius {:0.2f} and wheel_hollow_router_bit_radius {:0.2f}!".format(c['wheel_hollow_external_radius'], c['wheel_hollow_internal_radius'], c['wheel_hollow_rbr']))) sys.exit(2) # wheel_hollow_leg_width if(c['wheel_hollow_leg_width']0): #print("dbg305: crenel_type {:s}".format(c['crenel_type'])) if(c['crenel_type']=='rectangle'): if(math.sqrt((c['crenel_radius']+c['crenel_height'])**2+(c['crenel_width']/2)**2)> minimal_gear_profile_radius-radian_epsilon): - print("ERR298: Error, crenel_radius {:0.3f}, crenel_height {:0.3f} or crenel_width {:0.3f} are too big compare to minimal_gear_profile_radius {:0.3f}".format(c['crenel_radius'], c['crenel_height'], c['crenel_width'], minimal_gear_profile_radius)) + six.print_(("ERR298: Error, crenel_radius {:0.3f}, crenel_height {:0.3f} or crenel_width {:0.3f} are too big compare to minimal_gear_profile_radius {:0.3f}".format(c['crenel_radius'], c['crenel_height'], c['crenel_width'], minimal_gear_profile_radius))) sys.exit(2) elif(c['crenel_type']=='circle'): if((c['crenel_radius']+c['crenel_width']/2)>minimal_gear_profile_radius-radian_epsilon): - print("ERR311: Error, crenel_radius {:0.3f} or crenel_width {:0.3f} are too big compare to minimal_gear_profile_radius {:0.3f}".format(c['crenel_radius'], c['crenel_width'], minimal_gear_profile_radius)) + six.print_(("ERR311: Error, crenel_radius {:0.3f} or crenel_width {:0.3f} are too big compare to minimal_gear_profile_radius {:0.3f}".format(c['crenel_radius'], c['crenel_width'], minimal_gear_profile_radius))) sys.exit(2) if(c['crenel_radius']2*c['crenel_radius']-radian_epsilon): - print("ERR304: Error, crenel_width {:0.3f} is too big compare to crenel_radius {:0.3f}".format(c['crenel_width'], c['crenel_radius'])) + six.print_(("ERR304: Error, crenel_width {:0.3f} is too big compare to crenel_radius {:0.3f}".format(c['crenel_width'], c['crenel_radius']))) sys.exit(2) c['crenel_half_width_angle'] = math.asin(c['crenel_width']/(2*c['crenel_radius'])) if(c['crenel_half_width_angle']*2.2>crenel_increment_angle): - print("ERR305: Error, the crenel_increment_angle {:0.3f} or crenel_width {:0.3f} are too big!".format(crenel_increment_angle, c['crenel_width'])) + six.print_(("ERR305: Error, the crenel_increment_angle {:0.3f} or crenel_width {:0.3f} are too big!".format(crenel_increment_angle, c['crenel_width']))) sys.exit(2) if(c['crenel_width']<3.2*c['crenel_rbr']): - print("ERR308: Error, crenel_width {:0.3f} is too small compare to crenel_router_bit_radius {:0.3f}".format(c['crenel_width'], c['crenel_rbr'])) + six.print_(("ERR308: Error, crenel_width {:0.3f} is too small compare to crenel_router_bit_radius {:0.3f}".format(c['crenel_width'], c['crenel_rbr']))) sys.exit(2) ### crenel preparation @@ -341,7 +342,7 @@ def marked_circle_crenel(ai_x, ai_y, ai_radius, ai_orientation, ai_router_bit_ra #r_mcc = cnc25d_api.cnc_cut_outline(cnc25d_api.outline_rotate(A_mcc, ai_x, ai_y, ai_orientation), "marked_circle_crenel") r_mcc = cnc25d_api.outline_rotate(A_mcc, ai_x, ai_y, ai_orientation) else: - print("ERR182: Error, ai_mark_type {:d} doesn't exist".format(ai_mark_type)) + six.print_(("ERR182: Error, ai_mark_type {:d} doesn't exist".format(ai_mark_type))) sys.exit(2) return(r_mcc) @@ -442,7 +443,7 @@ def gearwheel_2d_construction(c): wh_angle = 2*math.pi/c['wheel_hollow_leg_number'] wh_leg_top_angle1 = math.asin(float(c['wheel_hollow_leg_width']/2.0+c['wheel_hollow_rbr'])/(c['wheel_hollow_external_radius']-c['wheel_hollow_rbr'])) if(wh_angle<2*wh_leg_top_angle1+radian_epsilon): - print("ERR664: Error, wh_angle {:0.2f} too small compare to wh_leg_top_angle1 {:0.2f}!".format(wh_angle, wh_leg_top_angle1)) + six.print_(("ERR664: Error, wh_angle {:0.2f} too small compare to wh_leg_top_angle1 {:0.2f}!".format(wh_angle, wh_leg_top_angle1))) sys.exit(2) wh_leg_bottom_angle1 = math.asin(float(c['wheel_hollow_leg_width']/2.0+c['wheel_hollow_rbr'])/(c['wheel_hollow_internal_radius']+c['wheel_hollow_rbr'])) #wh_leg_top_angle2 = math.asin((c['wheel_hollow_leg_width']/2)/c['wheel_hollow_external_radius']) diff --git a/cnc25d/gimbal.py b/cnc25d/gimbal.py index e841af6..2125e41 100644 --- a/cnc25d/gimbal.py +++ b/cnc25d/gimbal.py @@ -29,7 +29,8 @@ # header for Python / FreeCAD compatibility ################################################################ -import cnc25d_api +from . import cnc25d_api +import six cnc25d_api.importing_freecad() #print("FreeCAD.Version:", FreeCAD.Version()) @@ -52,9 +53,9 @@ #import svgwrite #from dxfwrite import DXFEngine # cnc25d -import bell_bagel_assembly -import cross_cube -import angles +from . import bell_bagel_assembly +from . import cross_cube +from . import angles ################################################################ @@ -110,7 +111,7 @@ def gimbal_constraint_check(c): ### if((c['bottom_angle']!=0)or(c['top_angle']!=0)): if((c['pan_angle']!=0)or(c['tilt_angle']!=0)): - print("ERR145: Error, roll-pitch angles {:0.3f} {:0.3f} and pan-tilt angles {:0.3f} {:0.3f} are set together".format(c['bottom_angle'], c['top_angle'], c['pan_angle'], c['tilt_angle'])) + six.print_(("ERR145: Error, roll-pitch angles {:0.3f} {:0.3f} and pan-tilt angles {:0.3f} {:0.3f} are set together".format(c['bottom_angle'], c['top_angle'], c['pan_angle'], c['tilt_angle']))) sys.exit(2) if((c['pan_angle']!=0)or(c['tilt_angle']!=0)): (a1, a2) = angles.pan_tilt_to_roll_pitch(c['pan_angle'], c['tilt_angle']) @@ -119,24 +120,24 @@ def gimbal_constraint_check(c): (b1, b2) = angles.roll_pitch_to_pan_tilt(c['bottom_angle'], c['top_angle']) (a1, a2) = angles.pan_tilt_to_roll_pitch(b1, b2) if((abs(c['bottom_angle']-a1)>radian_epsilon)or(abs(c['top_angle']-a2)>radian_epsilon)): - print("ERR154: Internal error in angle conversion: a1 {:0.3f} {:0.3f} a2 {:0.3f} {:0.3f}".format(c['bottom_angle'], a1, c['top_angle'], a2)) + six.print_(("ERR154: Internal error in angle conversion: a1 {:0.3f} {:0.3f} a2 {:0.3f} {:0.3f}".format(c['bottom_angle'], a1, c['top_angle'], a2))) sys.exit(2) c['b3'] = angles.roll_pitch_pan_tilt_drift_angle(c['bottom_angle'], c['top_angle']) # if(abs(c['bottom_angle'])>0.7*math.pi): - print("ERR133: Error, bottom_angle {:0.3f} absolute value is too big".format(c['bottom_angle'])) + six.print_(("ERR133: Error, bottom_angle {:0.3f} absolute value is too big".format(c['bottom_angle']))) sys.exit(2) if(abs(c['top_angle'])>0.7*math.pi): - print("ERR136: Error, top_angle {:0.3f} absolute value is too big".format(c['top_angle'])) + six.print_(("ERR136: Error, top_angle {:0.3f} absolute value is too big".format(c['top_angle']))) sys.exit(2) if(abs(c['bottom_angle'])+abs(c['top_angle'])>1.1*math.pi): - print("ERR139: Error, bottom_angle {:0.3f} and top_angle {:0.3f} absolute values can not be so large at the same time".format(c['bottom_angle'], c['top_angle'])) + six.print_(("ERR139: Error, bottom_angle {:0.3f} and top_angle {:0.3f} absolute values can not be so large at the same time".format(c['bottom_angle'], c['top_angle']))) sys.exit(2) # pan-tilt c['pan_angle'] = b1 c['tilt_angle'] = b2 if(c['tilt_angle']>0.6*math.pi): - print("ERR147: Error, tilt_angle {:0.3f} is to big".format(c['tilt_angle'])) + six.print_(("ERR147: Error, tilt_angle {:0.3f} is to big".format(c['tilt_angle']))) sys.exit(2) return(c) diff --git a/cnc25d/importing_freecad.py b/cnc25d/importing_freecad.py index ea5f893..6cbb064 100644 --- a/cnc25d/importing_freecad.py +++ b/cnc25d/importing_freecad.py @@ -38,6 +38,7 @@ ################################################################ import sys, os +import six ################################################################ # function @@ -61,7 +62,7 @@ def importing_freecad(): freecad_path=p if(freecad_path==''): print("ERR070: Error, the FreeCAD library path has not been found!") - print("Add the path of the directory containing FreeCAD.so to the variable FREECADPATH in the file {:s}".format(__FILE__)) + six.print_(("Add the path of the directory containing FreeCAD.so to the variable FREECADPATH in the file {:s}".format(__FILE__))) sys.exit(2) #print("dbg101: add FREECADPATH to sys.path") sys.path.append(freecad_path) @@ -77,6 +78,6 @@ def importing_freecad(): if(__name__ == "__main__"): importing_freecad() - print("FreeCAD.Version:", FreeCAD.Version()) + six.print_(("FreeCAD.Version:", FreeCAD.Version())) FreeCAD.Console.PrintMessage("Hello from PrintMessage!\n") diff --git a/cnc25d/low_torque_transmission.py b/cnc25d/low_torque_transmission.py index 0adc966..923bd14 100644 --- a/cnc25d/low_torque_transmission.py +++ b/cnc25d/low_torque_transmission.py @@ -29,7 +29,8 @@ # header for Python / FreeCAD compatibility ################################################################ -import cnc25d_api +from . import cnc25d_api +import six cnc25d_api.importing_freecad() #print("FreeCAD.Version:", FreeCAD.Version()) @@ -52,9 +53,9 @@ #import svgwrite #from dxfwrite import DXFEngine # cnc25d -import gearring -import gearwheel -import gear_profile # to get the high-level parameter to find the angle position +from . import gearring +from . import gearwheel +from . import gear_profile # to get the high-level parameter to find the angle position #import axle_lid ################################################################ @@ -314,15 +315,15 @@ def ltt_constraint_check(c): if(c['planet_nb']==0): c['planet_nb'] = c['planet_number_max'] if(c['planet_nb']>c['planet_number_max']): - print("ERR247: Error, planet_nb {:d} is bigger than planet_number_max {:d}".format(c['planet_nb'], c['planet_number_max'])) + six.print_(("ERR247: Error, planet_nb {:d} is bigger than planet_number_max {:d}".format(c['planet_nb'], c['planet_number_max']))) sys.exit(2) if(c['planet_nb']<1): - print("ERR251: Error, planet_nb {:d} must be bigger or equal to 1".format(c['planet_nb'])) + six.print_(("ERR251: Error, planet_nb {:d} must be bigger or equal to 1".format(c['planet_nb']))) sys.exit(2) # epicyclic fitting epicyclic_tooth_check = (2*(c['sun_gear_tooth_nb'] + c['planet_gear_tooth_nb'])) % c['planet_nb'] if(epicyclic_tooth_check != 0): - print("WARN243: Warning, not respected epicyclic-gearing-tooth-nb relation: 2*(sun_gear_tooth_nb {:d} + planet_gear_tooth_nb {:d}) % planet_nb {:d} == {:d} (should be 0)".format(c['sun_gear_tooth_nb'], c['planet_gear_tooth_nb'], c['planet_nb'], epicyclic_tooth_check)) + six.print_(("WARN243: Warning, not respected epicyclic-gearing-tooth-nb relation: 2*(sun_gear_tooth_nb {:d} + planet_gear_tooth_nb {:d}) % planet_nb {:d} == {:d} (should be 0)".format(c['sun_gear_tooth_nb'], c['planet_gear_tooth_nb'], c['planet_nb'], epicyclic_tooth_check))) c['planet_angle_inc'] = 2*math.pi/c['planet_nb'] c['planet_circle_radius'] = (c['sun_gear_tooth_nb'] + c['planet_gear_tooth_nb'])*c['gear_module']/2.0 c['planet_angle_position'] = [] @@ -355,15 +356,15 @@ def ltt_constraint_check(c): c['sun_oriantation_angles'].append(i_gp.get_constraint()['second_positive_initial_angle']) #c['sun_oriantation_angles'].append(math.fmod(i_gp.get_constraint()['second_positive_initial_angle']+sun_half_tooth_angle, 2*sun_half_tooth_angle)-sun_half_tooth_angle) # it is better to do this normaization when comparing if(abs(sun_x_position - 0.0)>radian_epsilon): - print("ERR286: Error, sun_x_position {:0.3f} is not at the expected coordinate 0.0".format(sun_x_position)) + six.print_(("ERR286: Error, sun_x_position {:0.3f} is not at the expected coordinate 0.0".format(sun_x_position))) sys.exit(2) if(abs(sun_y_position - 0.0)>radian_epsilon): - print("ERR289: Error, sun_y_position {:0.3f} is not at the expected coordinate 0.0".format(sun_y_position)) + six.print_(("ERR289: Error, sun_y_position {:0.3f} is not at the expected coordinate 0.0".format(sun_y_position))) sys.exit(2) #if(abs(c['sun_oriantation_angles'][i]-c['sun_oriantation_angles'][0])>radian_epsilon): angle_diff = math.fmod(c['sun_oriantation_angles'][i]-c['sun_oriantation_angles'][0]+11*sun_half_tooth_angle, 2*sun_half_tooth_angle)-sun_half_tooth_angle # might habe issue when the difference is negative if(abs(angle_diff)>radian_epsilon): - print("ERR293: Error, {:d}-sun_oriantation_angles {:0.3f} is different from 0-sun_oriantation_angles {:0.3f}".format(i, c['sun_oriantation_angles'][i], c['sun_oriantation_angles'][0])) + six.print_(("ERR293: Error, {:d}-sun_oriantation_angles {:0.3f} is different from 0-sun_oriantation_angles {:0.3f}".format(i, c['sun_oriantation_angles'][i], c['sun_oriantation_angles'][0]))) #print("dbg306: sun_half_tooth_angle:", sun_half_tooth_angle, 2*sun_half_tooth_angle, i_gp.get_constraint()['second_pi_module_angle']) #print("dbg307: sun_oriantation_angles:", c['sun_oriantation_angles']) #print("dbg369: angle_diff:", angle_diff) @@ -374,24 +375,24 @@ def ltt_constraint_check(c): c['sun_axle_radius'] = c['sun_axle_diameter']/2.0 c['sun_gear_hollow_diameter'] = c['gear_module']*(c['sun_gear_tooth_nb']-3) if(c['sun_axle_diameter']+2*c['sun_spacer_length']>c['sun_gear_hollow_diameter']): - print("ERR310: Error, sun_axle_diameter {:0.3f} or sun_spacer_length {:0.3f} are too big compare to sun_gear_hollow_diameter {:0.3f}".format(c['sun_axle_diameter'], c['sun_spacer_length'], c['sun_gear_hollow_diameter'])) + six.print_(("ERR310: Error, sun_axle_diameter {:0.3f} or sun_spacer_length {:0.3f} are too big compare to sun_gear_hollow_diameter {:0.3f}".format(c['sun_axle_diameter'], c['sun_spacer_length'], c['sun_gear_hollow_diameter']))) sys.exit(2) # planet axle and spacer c['planet_axle_radius'] = c['planet_axle_diameter']/2.0 c['planet_gear_hollow_diameter'] = c['gear_module']*(c['planet_gear_tooth_nb']-3) if(c['planet_axle_diameter']+2*c['planet_spacer_length']>c['planet_gear_hollow_diameter']): - print("ERR311: Error, planet_axle_diameter {:0.3f} or planet_spacer_length {:0.3f} are too big compare to planet_gear_hollow_diameter {:0.3f}".format(c['planet_axle_diameter'], c['planet_spacer_length'], c['planet_gear_hollow_diameter'])) + six.print_(("ERR311: Error, planet_axle_diameter {:0.3f} or planet_spacer_length {:0.3f} are too big compare to planet_gear_hollow_diameter {:0.3f}".format(c['planet_axle_diameter'], c['planet_spacer_length'], c['planet_gear_hollow_diameter']))) sys.exit(2) # planet_carrier axle and spacer c['planet_carrier_axle_radius'] = c['planet_carrier_axle_diameter']/2.0 if(c['planet_carrier_axle_diameter']+2*c['planet_carrier_spacer_length']>c['planet_gear_hollow_diameter']): - print("ERR315: Error, planet_carrier_axle_diameter {:0.3f} or planet_carrier_spacer_length {:0.3f} are too big compare to planet_gear_hollow_diameter {:0.3f}".format(c['planet_carrier_axle_diameter'], c['planet_carrier_spacer_length'], c['planet_gear_hollow_diameter'])) + six.print_(("ERR315: Error, planet_carrier_axle_diameter {:0.3f} or planet_carrier_spacer_length {:0.3f} are too big compare to planet_gear_hollow_diameter {:0.3f}".format(c['planet_carrier_axle_diameter'], c['planet_carrier_spacer_length'], c['planet_gear_hollow_diameter']))) sys.exit(2) if(c['planet_carrier_axle_holder_diameter']>c['planet_gear_hollow_diameter']): - print("ERR318: Error, planet_carrier_axle_holder_diameter {:0.3f} is too big compare to planet_gear_hollow_diameter {:0.3f}".format(c['planet_carrier_axle_holder_diameter'], c['planet_gear_hollow_diameter'])) + six.print_(("ERR318: Error, planet_carrier_axle_holder_diameter {:0.3f} is too big compare to planet_gear_hollow_diameter {:0.3f}".format(c['planet_carrier_axle_holder_diameter'], c['planet_gear_hollow_diameter']))) sys.exit(2) if(c['planet_axle_diameter']+2*c['planet_spacer_length']>c['planet_carrier_axle_holder_diameter']): - print("ERR321: Error, planet_carrier_axle_holder_diameter {:0.3f} is too small compare to planet_axle_diameter {:0.3f} and planet_spacer_length {:0.3f}".format(c['planet_axle_diameter'], c['planet_spacer_length'], c['planet_carrier_axle_holder_diameter'])) + six.print_(("ERR321: Error, planet_carrier_axle_holder_diameter {:0.3f} is too small compare to planet_axle_diameter {:0.3f} and planet_spacer_length {:0.3f}".format(c['planet_axle_diameter'], c['planet_spacer_length'], c['planet_carrier_axle_holder_diameter']))) sys.exit(2) c['planet_carrier_axle_holder_radius'] = c['planet_carrier_axle_holder_diameter']/2.0 # planet_carrier_external_diameter @@ -400,10 +401,10 @@ def ltt_constraint_check(c): c['planet_carrier_external_diameter'] = c['planet_carrier_external_diameter_max'] c['planet_carrier_external_radius'] = c['planet_carrier_external_diameter']/2.0 if(c['planet_carrier_external_diameter']>c['planet_carrier_external_diameter_max']): - print("ERR329: Error, planet_carrier_external_diameter {:0.3f} is bigger than planet_carrier_external_diameter_max {:0.3f}".format(c['planet_carrier_external_diameter'], c['planet_carrier_external_diameter_max'])) + six.print_(("ERR329: Error, planet_carrier_external_diameter {:0.3f} is bigger than planet_carrier_external_diameter_max {:0.3f}".format(c['planet_carrier_external_diameter'], c['planet_carrier_external_diameter_max']))) sys.exit(2) if(c['planet_carrier_external_radius']c['planet_carrier_external_diameter']-radian_epsilon): - print("ERR345: Error, planet_carrier_internal_diameter {:0.3f} is bigger than planet_carrier_external_diameter {:0.3f}".format(c['planet_carrier_internal_diameter'], c['planet_carrier_external_diameter'])) + six.print_(("ERR345: Error, planet_carrier_internal_diameter {:0.3f} is bigger than planet_carrier_external_diameter {:0.3f}".format(c['planet_carrier_internal_diameter'], c['planet_carrier_external_diameter']))) sys.exit(2) # planet_carrier_rear_smooth_radius if(c['planet_carrier_rear_smooth_radius']min(c['planet_carrier_internal_radius'], c['planet_carrier_axle_holder_radius'])): - print("ERR351: Error, planet_carrier_rear_smooth_radius {:0.3f} is too big compare to planet_carrier_internal_radius {:0.3f} and planet_carrier_axle_holder_radius {:0.3f}".format(c['planet_carrier_rear_smooth_radius'], c['planet_carrier_internal_radius'], c['planet_carrier_axle_holder_radius'])) + six.print_(("ERR351: Error, planet_carrier_rear_smooth_radius {:0.3f} is too big compare to planet_carrier_internal_radius {:0.3f} and planet_carrier_axle_holder_radius {:0.3f}".format(c['planet_carrier_rear_smooth_radius'], c['planet_carrier_internal_radius'], c['planet_carrier_axle_holder_radius']))) sys.exit(2) # planet_carrier_middle_clearance_diameter c['planet_carrier_middle_clearance_diameter_min'] = c['gear_module']*(c['planet_gear_tooth_nb']+4) @@ -429,7 +430,7 @@ def ltt_constraint_check(c): c['planet_carrier_middle_clearance_diameter'] = c['planet_carrier_middle_clearance_diameter_min'] c['planet_carrier_middle_clearance_radius'] = c['planet_carrier_middle_clearance_diameter']/2.0 if(c['planet_carrier_middle_clearance_diameter']c['planet_carrier_external_radius']-radian_epsilon): - print("ERR480: Error, hexagon_length {:0.3f} is too big compare to planet_carrier_external_diameter {:0.3f}".format(c['hexagon_length'], c['planet_carrier_external_diameter'])) + six.print_(("ERR480: Error, hexagon_length {:0.3f} is too big compare to planet_carrier_external_diameter {:0.3f}".format(c['hexagon_length'], c['planet_carrier_external_diameter']))) sys.exit(2) # hexagon_smooth_radius if(c['hexagon_smooth_radius']c['hexagon_length']/2.0-radian_epsilon): - print("ERR486: Error, hexagon_smooth_radius {:0.3f} is too big compare to hexagon_length {:0.3f}".format(c['hexagon_smooth_radius'], c['hexagon_length'])) + six.print_(("ERR486: Error, hexagon_smooth_radius {:0.3f} is too big compare to hexagon_length {:0.3f}".format(c['hexagon_smooth_radius'], c['hexagon_length']))) sys.exit(2) # output_cover_width, output_holder_width, hexagon_width c['output_holder_width2'] = c['output_holder_width'] + c['output_cover_width'] c['output_cover_depth'] = c['hexagon_width'] - c['output_holder_width'] if(c['output_cover_depth']<0): - print("ERR494: Error, output_cover_depth {:0.3f} < 0. output_cover_width{:0.3f} or hexagon_width {:0.3f} too small or output_holder_width {:0.3f} too big".format(c['output_cover_depth'], c['output_cover_width'], c['hexagon_width'], c['output_holder_width'])) + six.print_(("ERR494: Error, output_cover_depth {:0.3f} < 0. output_cover_width{:0.3f} or hexagon_width {:0.3f} too small or output_holder_width {:0.3f} too big".format(c['output_cover_depth'], c['output_cover_width'], c['hexagon_width'], c['output_holder_width']))) sys.exit(2) if(c['output_cover_depth']>c['output_cover_width']): - print("ERR497: Error, output_cover_depth {:0.3f} is too big compare to output_cover_width {:0.3f}".format(c['output_cover_depth'], c['output_cover_width'])) + six.print_(("ERR497: Error, output_cover_depth {:0.3f} is too big compare to output_cover_width {:0.3f}".format(c['output_cover_depth'], c['output_cover_width']))) sys.exit(2) if(c['output_cover_depth']>c['input_slack']): - print("ERR500: Error, input_slack {:0.3f} is too small compare to output_cover_depth {:0.3f}".format(c['input_slack'], c['output_cover_depth'])) + six.print_(("ERR500: Error, input_slack {:0.3f} is too small compare to output_cover_depth {:0.3f}".format(c['input_slack'], c['output_cover_depth']))) sys.exit(2) # output_cover_radius_slack c['holder_radius'] = i_gr.get_constraint()['holder_radius'] c['output_cover_radius'] = c['planet_carrier_external_radius']+c['output_cover_radius_slack'] if(c['output_cover_radius']>c['holder_radius']-radian_epsilon): - print("ERR508: Error, output_cover_radius_slack {:0.3f} is too big compare to planet_carrier_external_radius {:0.3f} and holder_radius {:0.3f}".format(c['output_cover_radius_slack'], c['planet_carrier_external_radius'], c['holder_radius'])) + six.print_(("ERR508: Error, output_cover_radius_slack {:0.3f} is too big compare to planet_carrier_external_radius {:0.3f} and holder_radius {:0.3f}".format(c['output_cover_radius_slack'], c['planet_carrier_external_radius'], c['holder_radius']))) sys.exit(2) c['output_holder_radius'] = c['holder_radius'] - c['output_holder_thickness'] if(c['output_holder_radius']c['holder_radius']): - print("ERR519: Error, axle_holder_D {:0.3f} or axle_holder_B {:0.3f} are too big compare to holder_radius {:0.3f}".format(c['axle_holder_D'], c['axle_holder_B'], c['holder_radius'])) + six.print_(("ERR519: Error, axle_holder_D {:0.3f} or axle_holder_B {:0.3f} are too big compare to holder_radius {:0.3f}".format(c['axle_holder_D'], c['axle_holder_B'], c['holder_radius']))) sys.exit(2) c['output_axle_cylinder_width'] = c['axle_holder_A'] + c['axle_holder_C'] c['output_axle_cylinder_thickness'] = c['axle_holder_D']/2.0 - c['output_axle_radius'] @@ -608,33 +609,33 @@ def sub_fitting_square(ai_r, ai_l1, ai_l2): # input_axle_diameter c['input_axle_radius'] = c['input_axle_diameter']/2.0 if(c['input_axle_radius']>c['sun_axle_radius']): - print("ERR521: Error, input_axle_radius {:0.3f} is too big compare to sun_axle_radius {:0.3f}".format(c['input_axle_radius'], c['sun_axle_radius'])) + six.print_(("ERR521: Error, input_axle_radius {:0.3f} is too big compare to sun_axle_radius {:0.3f}".format(c['input_axle_radius'], c['sun_axle_radius']))) sys.exit(2) # input_sun_width c['input_sun_width_min'] = c['sun_width'] if(c['input_sun_width']==0): c['input_sun_width'] = c['input_sun_width_min'] if(c['input_sun_width']c['holder_radius']): - print("ERR541: Error, motor_holder_E {:0.3f} or motor_holder_B {:0.3f} are too big compare to holder_radius {:0.3f}".format(c['motor_holder_E'], c['motor_holder_B'], c['holder_radius'])) + six.print_(("ERR541: Error, motor_holder_E {:0.3f} or motor_holder_B {:0.3f} are too big compare to holder_radius {:0.3f}".format(c['motor_holder_E'], c['motor_holder_B'], c['holder_radius']))) sys.exit(2) motor_xy_width_min = c['motor_x_width'] if(c['motor_shape_rectangle_ncircle']): motor_xy_width_min = min(c['motor_x_width'], c['motor_y_width']) if(c['motor_holder_leg_width']>motor_xy_width_min/4.0): - print("ERR545: Error, motor_holder_leg_width {:0.3f} is too big compare to motor_xy_width_min {:0.3f}".format(c['motor_holder_leg_width'], motor_xy_width_min)) + six.print_(("ERR545: Error, motor_holder_leg_width {:0.3f} is too big compare to motor_xy_width_min {:0.3f}".format(c['motor_holder_leg_width'], motor_xy_width_min))) sys.exit(2) c['motor_holder_leg_x'] = c['motor_holder_A'] + c['motor_holder_C'] + c['motor_holder_D'] c['motor_holder_leg_y'] = c['motor_holder_B'] + c['motor_holder_E'] diff --git a/cnc25d/motor_lid.py b/cnc25d/motor_lid.py index 81750d8..cd2dfbb 100644 --- a/cnc25d/motor_lid.py +++ b/cnc25d/motor_lid.py @@ -29,7 +29,8 @@ # header for Python / FreeCAD compatibility ################################################################ -import cnc25d_api +from . import cnc25d_api +import six cnc25d_api.importing_freecad() #print("FreeCAD.Version:", FreeCAD.Version()) @@ -52,7 +53,7 @@ #import svgwrite #from dxfwrite import DXFEngine # cnc25d -import axle_lid +from . import axle_lid ################################################################ @@ -190,11 +191,11 @@ def motor_lid_constraint_check(c): if(c['smoothing_radius']==0): c['smoothing_radius'] = c['cnc_router_bit_radius'] if(c['smoothing_radius']0): if(c['fastening_BC_external_radius']c['fastening_BC_bottom_position_radius']): - print("ERR327: Error, fastening_BC_bottom_position_radius {:0.3f} is too small compare to fastening_BC_external_radius {:0.3f} and fastening_BC_hole_radius {:0.3f}".format(c['fastening_BC_bottom_position_radius'], c['fastening_BC_external_radius'], c['fastening_BC_hole_radius'])) + six.print_(("ERR327: Error, fastening_BC_bottom_position_radius {:0.3f} is too small compare to fastening_BC_external_radius {:0.3f} and fastening_BC_hole_radius {:0.3f}".format(c['fastening_BC_bottom_position_radius'], c['fastening_BC_external_radius'], c['fastening_BC_hole_radius']))) sys.exit(2) if((c['fastening_BC_external_radius']+c['fastening_BC_hole_radius'])>c['fastening_BC_top_position_radius']): - print("ERR330: Error, fastening_BC_top_position_radius {:0.3f} is too small compare to fastening_BC_external_radius {:0.3f} and fastening_BC_hole_radius {:0.3f}".format(c['fastening_BC_top_position_radius'], c['fastening_BC_external_radius'], c['fastening_BC_hole_radius'])) + six.print_(("ERR330: Error, fastening_BC_top_position_radius {:0.3f} is too small compare to fastening_BC_external_radius {:0.3f} and fastening_BC_hole_radius {:0.3f}".format(c['fastening_BC_top_position_radius'], c['fastening_BC_external_radius'], c['fastening_BC_hole_radius']))) sys.exit(2) ### return(c) diff --git a/cnc25d/outline_backends.py b/cnc25d/outline_backends.py index 995013c..59c4058 100644 --- a/cnc25d/outline_backends.py +++ b/cnc25d/outline_backends.py @@ -28,14 +28,15 @@ # python behavior ################################################################ -from __future__ import division # to get float division + # to get float division ################################################################ # header for Python / FreeCAD compatibility ################################################################ -import importing_freecad +from . import importing_freecad +import six importing_freecad.importing_freecad() #print("FreeCAD.Version:", FreeCAD.Version()) @@ -52,12 +53,12 @@ import sys, argparse import svgwrite from dxfwrite import DXFEngine -import Tkinter +from six.moves import tkinter import time # for time.sleep to help Tkinter to finish properly -import display_backend -import cnc_outline # just used in figure_simple_display() for cnc_outline.outline_rotate, closed(), check_outline_format() and ideal_outline() -import export_2d # just for test enhancement -import design_help # just for get_effective_args() and mkdir_p +from . import display_backend +from . import cnc_outline # just used in figure_simple_display() for cnc_outline.outline_rotate, closed(), check_outline_format() and ideal_outline() +from . import export_2d # just for test enhancement +from . import design_help # just for get_effective_args() and mkdir_p ################################################################ @@ -80,7 +81,7 @@ def complete_circle(ai_center, ai_radius, ai_resolution): r_points = [] # calculation of the angle resolution: if(ai_resolution<3): - print("ERR821: The ai_resolution is smaller than 3. Current ai_resolution = {:d}".format(ai_resolution)) + six.print_(("ERR821: The ai_resolution is smaller than 3. Current ai_resolution = {:d}".format(ai_resolution))) sys.exit(2) #print("dbg424: ai_radius:", ai_radius) circle_resolution = int(ai_resolution * ai_radius) # circle resolution increase with the radius @@ -124,7 +125,7 @@ def arc_3_points_to_radius_center_angles(ai_start, ai_middle, ai_end): lbc = math.sqrt((ptcx-ptbx)**2+(ptcy-ptby)**2) if(labradian_epsilon)or(abs(IC-IA)>radian_epsilon)): - print("ERR748: Error in {:s}, the calculation of the center of the arc A,B,C is wrong! IA={:0.2f} IB={:0.2f} IC={:0.2f}".format(ai_error_msg_id, IA, IB, IC)) - print("dbg253: A= {:0.2f} {:0.2f} B= {:0.2f} {:0.2f} C= {:0.2f} {:0.2f} I= {:0.2f} {:0.2f}".format(AX,AY,BX,BY,CX,CY,IX,IY)) - print("dbg764: cos_e={:0.2f} sin_e={:0.2f} cos_f={:0.2f} sin_f={:0.2f}".format(cos_e, sin_e, cos_f, sin_f)) - print("dbg765: ixl={:0.2f} ixk={:0.2f} iyl={:0.2f} iyk={:0.2f}".format(ixl, ixk, iyl, iyk)) - print("dbg766: MX={:0.2f} MY={:0.2f} NX={:0.2f} NY={:0.2f}".format(MX,MY,NX,NY)) + six.print_(("ERR748: Error in {:s}, the calculation of the center of the arc A,B,C is wrong! IA={:0.2f} IB={:0.2f} IC={:0.2f}".format(ai_error_msg_id, IA, IB, IC))) + six.print_(("dbg253: A= {:0.2f} {:0.2f} B= {:0.2f} {:0.2f} C= {:0.2f} {:0.2f} I= {:0.2f} {:0.2f}".format(AX,AY,BX,BY,CX,CY,IX,IY))) + six.print_(("dbg764: cos_e={:0.2f} sin_e={:0.2f} cos_f={:0.2f} sin_f={:0.2f}".format(cos_e, sin_e, cos_f, sin_f))) + six.print_(("dbg765: ixl={:0.2f} ixk={:0.2f} iyl={:0.2f} iyk={:0.2f}".format(ixl, ixk, iyl, iyk))) + six.print_(("dbg766: MX={:0.2f} MY={:0.2f} NX={:0.2f} NY={:0.2f}".format(MX,MY,NX,NY))) sys.exit(2) # return r_arc_center_radius=(IX, IY, IA) @@ -134,7 +135,7 @@ def arc_center_radius_angles(ai_arc_pt1, ai_arc_pt2, ai_arc_pt3, ai_error_msg_id IB = math.sqrt((BX-IX)**2+(BY-IY)**2) IC = math.sqrt((CX-IX)**2+(CY-IY)**2) if((abs(IA-arc_radius)>radian_epsilon)or(abs(IB-arc_radius)>radian_epsilon)or(abs(IC-arc_radius)>radian_epsilon)): - print("ERR841: Error, in {:s}, I is not equidistant from A,B,C. arc_radius={:0.2f} IA={:0.2f} IB={:0.2f} IC={:0.2f}".format(ai_error_msg_id, arc_radius, IA, IB, IC)) + six.print_(("ERR841: Error, in {:s}, I is not equidistant from A,B,C. arc_radius={:0.2f} IA={:0.2f} IB={:0.2f} IC={:0.2f}".format(ai_error_msg_id, arc_radius, IA, IB, IC))) sys.exit(2) # calculation of the angle u=(Ix, IA) , v=(Ix, IB), w=(Ix, IC), d=(Ix, ID) and e=(Ix, IE) u = math.atan2(AY-IY, AX-IX) @@ -169,7 +170,7 @@ def triangulation(ai_A, ai_AC, ai_B, ai_BC, ai_D, ai_D_direction, ai_error_msg_i r_status = 0 # check the arguments if((ai_AC1): - print("ERR542: Error in {:s}, cos_BAC is out of [-1,1]! a={:0.2f} b={:0.2f} c={:0.2f} cos_BAC={:0.2f}".format(ai_error_msg_id, a, b, c, cos_BAC)) - print("dbg652: AX={:0.2f} AY={:0.2f} BX={:0.2f} BY={:0.2f}".format(AX,AY,BX,BY)) + six.print_(("ERR542: Error in {:s}, cos_BAC is out of [-1,1]! a={:0.2f} b={:0.2f} c={:0.2f} cos_BAC={:0.2f}".format(ai_error_msg_id, a, b, c, cos_BAC))) + six.print_(("dbg652: AX={:0.2f} AY={:0.2f} BX={:0.2f} BY={:0.2f}".format(AX,AY,BX,BY))) #sys.exit(2) r_status=2 return((0,0,r_status)) @@ -201,7 +202,7 @@ def triangulation(ai_A, ai_AC, ai_B, ai_BC, ai_D, ai_D_direction, ai_error_msg_i xAD = math.atan2(DY-AY, DX-AX) # atan2 avoid the problem of divided by zero BAD = math.fmod(xAD - xAB + 5*math.pi, 2*math.pi) - math.pi if(abs(BAD)radian_epsilon)or(abs(CY2-CY)>radian_epsilon)): - print("ERR686: Error in {:s}, the coordinate of C seems wrong! CX={:0.2f} CX2={:0.2f} CY={:0.2f} CY2={:0.2f}".format(ai_error_msg_id, CX, CX2, CY, CY2)) - print("dbg545: D {:0.2f} {:0.2f} ai_D_direction {:0.2f}".format(DX,DY, ai_D_direction)) - print("dbg512: BAC", BAC) - print("dbg513: xAB", xAB) + six.print_(("ERR686: Error in {:s}, the coordinate of C seems wrong! CX={:0.2f} CX2={:0.2f} CY={:0.2f} CY2={:0.2f}".format(ai_error_msg_id, CX, CX2, CY, CY2))) + six.print_(("dbg545: D {:0.2f} {:0.2f} ai_D_direction {:0.2f}".format(DX,DY, ai_D_direction))) + six.print_(("dbg512: BAC", BAC)) + six.print_(("dbg513: xAB", xAB)) #print("dbg514: AD", AD) - print("dbg515: BAD", BAD) - print("dbg516: xAC", xAC) - print("dbg517: AX {:0.2f} AY {:0.2f} b {:0.2f}".format(AX,AY, b)) - print("dbg522: ABC", ABC) - print("dbg523: xBA", xBA) + six.print_(("dbg515: BAD", BAD)) + six.print_(("dbg516: xAC", xAC)) + six.print_(("dbg517: AX {:0.2f} AY {:0.2f} b {:0.2f}".format(AX,AY, b))) + six.print_(("dbg522: ABC", ABC)) + six.print_(("dbg523: xBA", xBA)) #print("dbg524: BD", BD) - print("dbg525: ABD", ABD) - print("dbg526: xBC", xBC) - print("dbg527: BX {:0.2f} BY {:0.2f} a {:0.2f}".format(BX,BY, a)) + six.print_(("dbg525: ABD", ABD)) + six.print_(("dbg526: xBC", xBC)) + six.print_(("dbg527: BX {:0.2f} BY {:0.2f} a {:0.2f}".format(BX,BY, a))) sys.exit(2) r_C = (CX,CY,r_status) return(r_C) @@ -258,7 +259,7 @@ def line_equation(ai_A, ai_B, ai_error_msg_id): # calculation of the length AB lAB = math.sqrt((BX-AX)**2+(BY-AY)**2) if(lABai_R): # This error might occur when the sign of the tangent is wrong because of calculation impression. # That's why, we need to report the error instead of stopping on this error - print("ERR672: Error in {:s}, the line and the circle have no intersection! IP={:0.2f} ai_R={:0.2f}".format(ai_error_msg_id, IP, ai_R)) - print("dbg611: ai_AB:", ai_AB) - print("dbg612: ai_I:", ai_I) - print("dbg613: ai_R:", ai_R) - print("dbg614: ai_C:", ai_C) + six.print_(("ERR672: Error in {:s}, the line and the circle have no intersection! IP={:0.2f} ai_R={:0.2f}".format(ai_error_msg_id, IP, ai_R))) + six.print_(("dbg611: ai_AB:", ai_AB)) + six.print_(("dbg612: ai_I:", ai_I)) + six.print_(("dbg613: ai_R:", ai_R)) + six.print_(("dbg614: ai_C:", ai_C)) #sys.exit(2) line_circle_intersection_status=2 r_line_circle_intersection = (0, 0, line_circle_intersection_status) @@ -367,7 +368,7 @@ def line_circle_intersection(ai_AB, ai_I, ai_R, ai_C, ai_D_direction, ai_error_m cos_i = (C2X-PX)/C2P sin_i = (C2Y-PY)/C2P if(C2Pmath.pi-10*radian_epsilon)): # error then retry with -Q1_plus instead of Q1_plus - print("WARN682: Warning in {:s}, line_arc corner is smoothed with the other side because of a line_circle_intersection error!".format(ai_error_msg_id)) + six.print_(("WARN682: Warning in {:s}, line_arc corner is smoothed with the other side because of a line_circle_intersection error!".format(ai_error_msg_id))) (QX,QY, ACkQ) = line_distance_point(ai_pre_point, ai_current_point, -Q1_plus*ai_router_bit_request, ai_error_msg_id) tmpCX = CX + JS*math.cos(xAC+math.pi) tmpCY = CY + JS*math.sin(xAC+math.pi) (SX,SY, line_circle_intersection_status) = line_circle_intersection((AClx, ACly, ACkQ), (JX,JY),JS, (tmpCX,tmpCY), D_direction, ai_error_msg_id) # end of the retry. Continue the normal calculation recipe if(line_circle_intersection_status==2): - print("WARN684: Warning in {:s}, corner is not smoothed because of a line_circle_intersection error!".format(ai_error_msg_id)) - print("dbg681: ai_pre_point", ai_pre_point) - print("dbg683: ai_current_point", ai_current_point) - print("dbg684: ai_post_middle", ai_post_middle) - print("dbg685: ai_post_point", ai_post_point) - print("dbg686: ai_router_bit_request", ai_router_bit_request) - print("dbg623: AClx={:0.2f} ACly={:0.2f} ACkA={:0.2f} lAC={:0.2f} xAC={:0.2f}".format(AClx, ACly, ACkA, lAC, xAC)) - print("dbg688: JX={:0.2f} JY={:0.2f} R2={:0.2f} uw2={:0.2f} u2={:0.2f} w2={:0.2f}".format(JX, JY, R2, uw2, u2, w2)) - print("dbg689: o2={:0.2f} o3={:0.2f}".format(o2,o3)) - print("dbg691: tangent_angle", tangent_angle) - print("dbg692: JS={:0.2f}".format(JS)) - print("dbg711: QX={:0.2f} QY={:0.2f} ACkQ={:0.2f}".format(QX,QY,ACkQ)) - print("dbg693: in {:s}, xAC={:0.2f} R2={:0.2f} ai_router_bit_request={:0.2f}".format(ai_error_msg_id, xAC, R2, ai_router_bit_request)) + six.print_(("WARN684: Warning in {:s}, corner is not smoothed because of a line_circle_intersection error!".format(ai_error_msg_id))) + six.print_(("dbg681: ai_pre_point", ai_pre_point)) + six.print_(("dbg683: ai_current_point", ai_current_point)) + six.print_(("dbg684: ai_post_middle", ai_post_middle)) + six.print_(("dbg685: ai_post_point", ai_post_point)) + six.print_(("dbg686: ai_router_bit_request", ai_router_bit_request)) + six.print_(("dbg623: AClx={:0.2f} ACly={:0.2f} ACkA={:0.2f} lAC={:0.2f} xAC={:0.2f}".format(AClx, ACly, ACkA, lAC, xAC))) + six.print_(("dbg688: JX={:0.2f} JY={:0.2f} R2={:0.2f} uw2={:0.2f} u2={:0.2f} w2={:0.2f}".format(JX, JY, R2, uw2, u2, w2))) + six.print_(("dbg689: o2={:0.2f} o3={:0.2f}".format(o2,o3))) + six.print_(("dbg691: tangent_angle", tangent_angle)) + six.print_(("dbg692: JS={:0.2f}".format(JS))) + six.print_(("dbg711: QX={:0.2f} QY={:0.2f} ACkQ={:0.2f}".format(QX,QY,ACkQ))) + six.print_(("dbg693: in {:s}, xAC={:0.2f} R2={:0.2f} ai_router_bit_request={:0.2f}".format(ai_error_msg_id, xAC, R2, ai_router_bit_request))) #r_outline = [(ai_current_point[0], ai_current_point[1])] smooth_status = 2 sys.exit(2) @@ -551,11 +552,11 @@ def sub_smooth_corner_arc_arc(ai_pre_point, ai_pre_middle, ai_current_point, ai_ #r_outline = [] smooth_status = 0 if(abs(tangent_angle)math.pi-radian_epsilon): - print("WARN933: Warning in {:s}, the tangent_angle is too sharp! the corner cannot be smoothed.".format(ai_error_msg_id)) + six.print_(("WARN933: Warning in {:s}, the tangent_angle is too sharp! the corner cannot be smoothed.".format(ai_error_msg_id))) #r_outline = [(ai_current_point[0], ai_current_point[1])] smooth_status = 2 else: @@ -583,7 +584,7 @@ def sub_smooth_corner_arc_arc(ai_pre_point, ai_pre_middle, ai_current_point, ai_ #print("dbg693: bisector_angle {:0.2f} D_direction {:0.2f}".format(bisector_angle, D_direction)) (SX,SY, triangulation_status) = triangulation((IX,IY),IS,(JX,JY),JS,(CX,CY), D_direction, ai_error_msg_id) if(triangulation_status==2): - print("WARN693: Warning in {:s}, corner is not smoothed because of a triangulation error!".format(ai_error_msg_id)) + six.print_(("WARN693: Warning in {:s}, corner is not smoothed because of a triangulation error!".format(ai_error_msg_id))) #print("dbg681: ai_pre_point", ai_pre_point) #print("dbg682: ai_pre_middle", ai_pre_middle) #print("dbg683: ai_current_point", ai_current_point) @@ -632,13 +633,13 @@ def sub_enlarge_corner_line_arc(ai_pre_point, ai_current_point, ai_post_middle, MKX=0; MKY=0; GX=0; GY=0; HX=0; HY=0; NLX=0; NLY=0; enlarge_type_request_1=0; enlarge_type_request_2=0 (SX, SY, UX, UY, xSU, xSJ, router_bit_arc_uw, smooth_status) = sub_smooth_corner_line_arc(ai_pre_point, ai_current_point, ai_post_middle, ai_post_point, ai_router_bit_request, ai_error_msg_id) if(smooth_status!=1): - print("ERR977: Error in {:s}, the sub smooth corner get an error!".format(ai_error_msg_id)) + six.print_(("ERR977: Error in {:s}, the sub smooth corner get an error!".format(ai_error_msg_id))) sys.exit(2) enlarge_status = 2 else: #print("dbg553: router_bit_arc_uw:", router_bit_arc_uw) if(abs(router_bit_arc_uw)>math.pi): - print("ERR877: Error in {:s}, the sub smooth corner is englobed!".format(ai_error_msg_id)) + six.print_(("ERR877: Error in {:s}, the sub smooth corner is englobed!".format(ai_error_msg_id))) sys.exit(2) enlarge_status = 2 elif(abs(router_bit_arc_uw)0): (LX,LY, triangulation_status) = triangulation((JX,JY),R2, (FX,FY),ai_router_bit_request, (HX,HY), xSC+math.pi, ai_error_msg_id) if(triangulation_status==2): - print("ERR533: Error in {:s} with the triangulation_status!".format(ai_error_msg_id)) + six.print_(("ERR533: Error in {:s} with the triangulation_status!".format(ai_error_msg_id))) sys.exit(2) NLX = LX NLY = LY enlarge_type_request_2 = 2 lMN=math.sqrt((NLX-MKX)**2+(NLY-MKY)**2) if(lMNmath.pi): - print("ERR887: Error in {:s}, the sub smooth corner is englobed!".format(ai_error_msg_id)) + six.print_(("ERR887: Error in {:s}, the sub smooth corner is englobed!".format(ai_error_msg_id))) sys.exit(2) enlarge_status = 2 elif(abs(router_bit_arc_uw)0): (KX,KY, triangulation_status) = triangulation((IX,IY),R1,(FX,FY),ai_router_bit_request,(GX,GY), xSC+math.pi, ai_error_msg_id) if(triangulation_status==2): - print("ERR536: Error in {:s} with the triangulation_status!".format(ai_error_msg_id)) + six.print_(("ERR536: Error in {:s} with the triangulation_status!".format(ai_error_msg_id))) sys.exit(2) MKX = KX MKY = KY @@ -820,14 +821,14 @@ def sub_enlarge_corner_arc_arc(ai_pre_point, ai_pre_middle, ai_current_point, ai if(NH_deep>0): (LX,LY, triangulation_status) = triangulation((JX,JY),R2,(FX,FY),ai_router_bit_request,(HX,HY), xSC+math.pi, ai_error_msg_id) if(triangulation_status==2): - print("ERR533: Error in {:s} with the triangulation_status!".format(ai_error_msg_id)) + six.print_(("ERR533: Error in {:s} with the triangulation_status!".format(ai_error_msg_id))) sys.exit(2) NLX = LX NLY = LY enlarge_type_request_2 = 2 lMN=math.sqrt((NLX-MKX)**2+(NLY-MKY)**2) if(lMNradian_epsilon): - print("ERR375: Error in {:s}, O is not equidistant from A and C! lOA={:0.2f} l_OC={:0.2f}".format(ai_error_msg_id, lOA, lOC)) + six.print_(("ERR375: Error in {:s}, O is not equidistant from A and C! lOA={:0.2f} l_OC={:0.2f}".format(ai_error_msg_id, lOA, lOC))) sys.exit(2) if(lOAmath.pi-radian_epsilon): - print("ERR239: Error in {:s}, AC and the tangent Ti are collinear and in opposite direction. iAC={:0.2f} ti={:0.2f}".format(i_error_msg_id, iAC, ti)) + six.print_(("ERR239: Error in {:s}, AC and the tangent Ti are collinear and in opposite direction. iAC={:0.2f} ti={:0.2f}".format(i_error_msg_id, iAC, ti))) sys.exit(2) if(abs(rti)>math.pi/3): - print("WARN249: Warning in {:s}, AC and the tangent Ti are doing a large angle. Add itermediate points to remove this warning. iAC={:0.2f} ti={:0.2f}".format(i_error_msg_id, iAC, ti)) + six.print_(("WARN249: Warning in {:s}, AC and the tangent Ti are doing a large angle. Add itermediate points to remove this warning. iAC={:0.2f} ti={:0.2f}".format(i_error_msg_id, iAC, ti))) if(abs(rti)math.pi/2): - print("ERR639: Error in {:s}, the angle between AC and the tangent xAt is larger than pi/2. It doesn't look like a feasible curbe. xAC={:0.2f} xAt={:0.2f}".format(i_error_msg_id, xAC, xAt)) + six.print_(("ERR639: Error in {:s}, the angle between AC and the tangent xAt is larger than pi/2. It doesn't look like a feasible curbe. xAC={:0.2f} xAt={:0.2f}".format(i_error_msg_id, xAC, xAt))) sys.exit(2) if(abs(EtEA)>math.pi/2): - print("ERR638: Error in {:s}, the angle between EC and the tangent et is larger than pi/2. It doesn't look like a feasible curbe. xEC={:0.2f} xEt={:0.2f}".format(i_error_msg_id, xEC, xEt)) + six.print_(("ERR638: Error in {:s}, the angle between EC and the tangent et is larger than pi/2. It doesn't look like a feasible curbe. xEC={:0.2f} xEt={:0.2f}".format(i_error_msg_id, xEC, xEt))) sys.exit(2) if(abs(AtAE)>math.pi/3): - print("WARN649: Warning in {:s}, AC and the tangent xAt are doing a large angle. Add itermediate points to remove this warning. xAC={:0.2f} xAt={:0.2f}".format(i_error_msg_id, xAC, xAt)) + six.print_(("WARN649: Warning in {:s}, AC and the tangent xAt are doing a large angle. Add itermediate points to remove this warning. xAC={:0.2f} xAt={:0.2f}".format(i_error_msg_id, xAC, xAt))) if(abs(EtEA)>math.pi/3): - print("WARN648: Warning in {:s}, EC and the tangent xEt are doing a large angle. Add itermediate points to remove this warning. xEC={:0.2f} xEt={:0.2f}".format(i_error_msg_id, xEC, xEt)) + six.print_(("WARN648: Warning in {:s}, EC and the tangent xEt are doing a large angle. Add itermediate points to remove this warning. xEC={:0.2f} xEt={:0.2f}".format(i_error_msg_id, xEC, xEt))) if((abs(AtAE)0): - print("WARN669: Warning in {:s}, xAt and xEt are not one the side of (AE). It look like an inflexion. A line is generated for this segment. xAC={:0.2f} xAt={:0.2f} xEC={:0.2f} xEt={:0.2f} ".format(i_error_msg_id, xAC, xAt, xEC, xEt)) + six.print_(("WARN669: Warning in {:s}, xAt and xEt are not one the side of (AE). It look like an inflexion. A line is generated for this segment. xAC={:0.2f} xAt={:0.2f} xEC={:0.2f} xEt={:0.2f} ".format(i_error_msg_id, xAC, xAt, xEC, xEt))) r_outline.append((EX, EY)) # create a line-segment else: # C intersection of (AC) and (EC). it is the junction point between the two arcs (CX, CY, line_line_intersection_status) = line_line_intersection((AClx, ACly, ACk),(EClx, ECly, ECk), ai_error_msg_id) if(line_line_intersection_status==2): - print("ERR324: Error in {:s}, AC and EC are collinear!".format(ai_error_msg_id)) + six.print_(("ERR324: Error in {:s}, AC and EC are collinear!".format(ai_error_msg_id))) sys.exit(2) (BX, BY, xCt) = curve_arc(AX, AY, CX, CY, xAt, ai_router_bit_request, i_error_msg_id) if(abs(math.fmod(xCt-xAE+5*math.pi, 2*math.pi)-math.pi)>radian_epsilon): - print("ERR325: Error in {:s}, the first arc tangent in C is not parallel to AE! xCt={:0.2f} xAE={:0.2f}".format(ai_error_msg_id, xCt, xAE)) + six.print_(("ERR325: Error in {:s}, the first arc tangent in C is not parallel to AE! xCt={:0.2f} xAE={:0.2f}".format(ai_error_msg_id, xCt, xAE))) sys.exit(2) (DX, DY, xEt2) = curve_arc(CX, CY, EX, EY, xAE, ai_router_bit_request, i_error_msg_id) if(abs(math.fmod(xEt2-xEt+5*math.pi, 2*math.pi)-math.pi)>radian_epsilon): - print("ERR326: Error in {:s}, the second arc tangent in E is different from xEt! xEt={:0.2f} xEt2={:0.2f}".format(ai_error_msg_id, xEt, xEt2)) + six.print_(("ERR326: Error in {:s}, the second arc tangent in E is different from xEt! xEt={:0.2f} xEt2={:0.2f}".format(ai_error_msg_id, xEt, xEt2))) sys.exit(2) r_outline.append((BX, BY, CX, CY)) # create the first arc-segment r_outline.append((DX, DY, EX, EY)) # create the second arc-segment diff --git a/cnc25d/split_gearwheel.py b/cnc25d/split_gearwheel.py index fcfa732..a89a50e 100644 --- a/cnc25d/split_gearwheel.py +++ b/cnc25d/split_gearwheel.py @@ -30,7 +30,8 @@ # header for Python / FreeCAD compatibility ################################################################ -import cnc25d_api +from . import cnc25d_api +import six cnc25d_api.importing_freecad() #print("FreeCAD.Version:", FreeCAD.Version()) @@ -53,7 +54,7 @@ #import svgwrite #from dxfwrite import DXFEngine # cnc25d -import gear_profile +from . import gear_profile ################################################################ @@ -145,14 +146,14 @@ def split_gearwheel_constraint_check(c): c['split_rbr'] = c['cnc_router_bit_radius'] # c['low_split_type'] if(not c['low_split_type'] in ('circle', 'line')): - print("ERR216: Error, c['low_split_type'] {:s} is not valid!".format(c['low_split_type'])) + six.print_(("ERR216: Error, c['low_split_type'] {:s} is not valid!".format(c['low_split_type']))) sys.exit(2) # c['high_split_type'] if(not c['high_split_type'] in ('h', 'a')): - print("ERR220: Error, c['high_split_type'] {:s} is not valid!".format(c['high_split_type'])) + six.print_(("ERR220: Error, c['high_split_type'] {:s} is not valid!".format(c['high_split_type']))) sys.exit(2) if(c['split_nb']<2): - print("ERR188: Error, split_nb {:d} must be equal or bigger than 2".format(c['split_nb'])) + six.print_(("ERR188: Error, split_nb {:d} must be equal or bigger than 2".format(c['split_nb']))) sys.exit(2) #c['portion_angle'] = 2*math.pi/c['split_nb'] c['portion_angle'] = math.pi/c['split_nb'] @@ -178,7 +179,7 @@ def split_gearwheel_constraint_check(c): g1_ia = gear_profile_parameters['g1_param']['initial_angle'] g1_tl = gear_profile_parameters['g1_param']['top_land'] if(c['portion_angle']<(1.1*g1_pma)): - print("ERR219: Error, portion_angle {:0.3f} is too small compare to the pi_module_angle {:0.3f}".format(c['portion_angle'], g1_pma)) + six.print_(("ERR219: Error, portion_angle {:0.3f} is too small compare to the pi_module_angle {:0.3f}".format(c['portion_angle'], g1_pma))) sys.exit(2) # pre common calculation absolute_angle = [] @@ -235,7 +236,7 @@ def split_gearwheel_constraint_check(c): #print("dbg276: len(portion_gear_first_end) {:d} len(portion_gear_last_end) {:d}".format(len(c['portion_gear_first_end']), len(c['portion_gear_last_end']))) else: # no gear_profile, just a circle if(c['gear_primitive_diameter']